Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如果我使用同一个键两次推送userdata会发生什么?_C++_Lua_Lua Userdata - Fatal编程技术网

C++ 如果我使用同一个键两次推送userdata会发生什么?

C++ 如果我使用同一个键两次推送userdata会发生什么?,c++,lua,lua-userdata,C++,Lua,Lua Userdata,我想知道如果我使用同一个键将lightuserdata推入注册表两次会发生什么 我的代码: MyData*x,*y//假设这些是有效的指针 lua_pushstring(L,“我的数据”); lua_pushlightuserdata(L,静态_cast(x)); lua_可设置(L,lua_注册表索引); lua_pushstring(L,“我的数据”); lua_pushlightuserdata(L,静态_cast(y)); lua_可设置(L,lua_注册表索引); lua_pushst

我想知道如果我使用同一个键将lightuserdata推入注册表两次会发生什么

我的代码:

MyData*x,*y//假设这些是有效的指针
lua_pushstring(L,“我的数据”);
lua_pushlightuserdata(L,静态_cast(x));
lua_可设置(L,lua_注册表索引);
lua_pushstring(L,“我的数据”);
lua_pushlightuserdata(L,静态_cast(y));
lua_可设置(L,lua_注册表索引);
lua_pushstring(L,“我的数据”);
lua_gettable(L,lua_注册表索引);
MyData*data=static_cast(lua_tuserdata(L,-1));
//数据是x还是y?
以前按下的指针(
x
)是否会被新指针(
y
)替换


添加:有没有办法检查当前注册的键列表?

Lua注册表是一个普通的Lua表。您的代码相当于

registry.my_data = x
registry.my_data = y

因此,是的,在这两行之后,
registry.my_data
的值是
y

的值,要检查字段是否存在,请使用:
lua_getfield(L,lua_REGISTRYINDEX,“my_data”);如果(!lua_isnil(L,-1)){/*字段存在,则执行*/}lua_pop(L,1)操作