[英]What should a C function called from Lua that pushes a table return?
When writing a C function that pushes a table onto the stack as its return value to the Lua caller, what should it return in the C context? 当编写一个将表推入堆栈的C函数作为Lua调用者的返回值时,它应该在C上下文中返回什么? I know you are supposed to return the number of values that you are passing back to the Lua caller, but in the case of a table, is it 1 for the table reference, or do you need to account for the contents of the table?
我知道你应该返回你传递回Lua调用者的值的数量,但是对于表来说,表引用是1,还是需要考虑表的内容?
The method of passing back a table I am using is shown in " Pushing a Lua Table. " 传回我正在使用的表的方法显示在“ 推送Lua表”中。
You are only returning one lua value directly, so your C function should return 1. 你只是直接返回一个lua值,所以你的C函数应该返回1。
Something like this: 像这样的东西:
int my_table( luaState * L) {
lua_newtable(L);
lua_pushstring(L, "a_key");
lua_pushstring(L, "a_value");
lua_settable(L, -3);
return 1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.