我有一个std::list
对象,我想给 Lua 一个返回其多维位置的函数。所以我需要创建一个表的表:
{{1,2,3...,512}, {1,2,3...,512},...,512}
lua_newtable(L);
for (int i = 0; i < 512; i++)
{
lua_newtable(L);
lua_pushnumber(L, pos[i]);
lua_rawseti(L, -2, i);
lua_rawseti(L, -2, i+1);
for (int j = 0; j < 512; j++)
{
//pos[i][j]
}
}
我会尝试反复尝试,但由于我现在不知道如何调试它,所以我真的迷失了。
我认为您想创建尺寸为 512x512 的嵌套表(或矩阵)。
static int CreateMatrix( lua_State *L ) {
lua_newtable( L );
for( int i = 0; i < 512; i++ ) {
lua_pushnumber( L, i + 1 ); // parent table index
lua_newtable( L ); // child table
for( int j = 0; j < 512; j++ ) {
lua_pushnumber( L, j + 1 ); // this will be the child's index
lua_pushnumber( L, j + 1 ); // this will be the child's value
lua_settable( L, -3 );
}
lua_settable( L, -3 );
}
return 1;
}
您当然可以使用自己的值/索引。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)