mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add lua_lightuserdatatag
This commit is contained in:
parent
661734412f
commit
002aaf8dcf
3 changed files with 11 additions and 0 deletions
|
@ -163,6 +163,7 @@ LUA_API void* lua_tolightuserdatatagged(lua_State* L, int idx, int tag);
|
|||
LUA_API void* lua_touserdata(lua_State* L, int idx);
|
||||
LUA_API void* lua_touserdatatagged(lua_State* L, int idx, int tag);
|
||||
LUA_API int lua_userdatatag(lua_State* L, int idx);
|
||||
LUA_API int lua_lightuserdatatag(lua_State* L, int idx);
|
||||
LUA_API lua_State* lua_tothread(lua_State* L, int idx);
|
||||
LUA_API void* lua_tobuffer(lua_State* L, int idx, size_t* len);
|
||||
LUA_API const void* lua_topointer(lua_State* L, int idx);
|
||||
|
|
|
@ -536,6 +536,14 @@ int lua_userdatatag(lua_State* L, int idx)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int lua_lightuserdatatag(lua_State* L, int idx)
|
||||
{
|
||||
StkId o = index2addr(L, idx);
|
||||
if (ttislightuserdata(o))
|
||||
return o->extra[0];
|
||||
return -1;
|
||||
}
|
||||
|
||||
lua_State* lua_tothread(lua_State* L, int idx)
|
||||
{
|
||||
StkId o = index2addr(L, idx);
|
||||
|
|
|
@ -1675,10 +1675,12 @@ TEST_CASE("LightuserdataApi")
|
|||
void* value = (void*)0x12345678;
|
||||
|
||||
lua_pushlightuserdata(L, value);
|
||||
CHECK(lua_lightuserdatatag(L, -1) == 0);
|
||||
CHECK(lua_tolightuserdatatagged(L, -1, 0) == value);
|
||||
CHECK(lua_tolightuserdatatagged(L, -1, 1) == nullptr);
|
||||
|
||||
lua_pushlightuserdatatagged(L, value, 1);
|
||||
CHECK(lua_lightuserdatatag(L, -1) == 1);
|
||||
CHECK(lua_tolightuserdatatagged(L, -1, 0) == nullptr);
|
||||
CHECK(lua_tolightuserdatatagged(L, -1, 1) == value);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue