1

Now, I have two modules, CModule and CModule2. In CModule, My code like below:

static int RegisterTable(lua_State *L)
{
    luaL_checktype(L, 1, LUA_TTABLE);
    int iRef = luaL_ref(L, LUA_REGISTRYINDEX);
    lua_pushinteger(L, iRef);
    return 1;
}

I will get the registered table in the CModule2. In CModule2, My code like below:

int iRef = luaL_checkinteger(L, 1);
lua_rawgeti(L, LUA_REGISTRYINDEX, iRef);
size_t iLen = lua_objlen(L, -1);
printf("iLen:%d", iLen);
for (size_t i = 1; i <= iLen; ++iLen)
{
    lua_rawgeti(L, -1, i);
    int iValue = lua_tointeger(L, -1);
    lua_pop(L, 1);
    printf("%d", iValue);
}
    printf("\n");

But now. When I call the lua_objlen, I got nothing. Is there any error? If I register a function or a string value, it works well.

I call the CModule in Lua like this.

require "CModule"
require "CModule2"
local tbTest = {2, 4, 6, 8, 10}
local iRef1 = CModule.RegisterTable(tbTest)
CModule2.GetRegisteredTable(iRef1)

Why?

4

0 に答える 0