在C中创建二维Lua表示例

来源:互联网 发布:完美网络刷销量 编辑:程序博客网 时间:2024/06/17 01:31
// 创建二维数组Lua表void createLuaTable2(lua_State *L, const char* t){lua_newtable(L); // t//========================lua_pushinteger(L, 1); // t[1]lua_newtable(L); // p1// p1[1] = 100lua_pushinteger(L, 1);lua_pushinteger(L, 100);lua_settable(L, 3);// p1[2] = 200lua_pushinteger(L, 2);lua_pushinteger(L, 200);lua_settable(L, 3);// p1[3] = 300lua_pushinteger(L, 3);lua_pushinteger(L, 300);lua_settable(L, 3);// t[1] = p1lua_settable(L, 1);//==========================lua_pushinteger(L, 2); // t[2]lua_newtable(L); // p2// p2[1] = 'AAAA'lua_pushinteger(L, 1);lua_pushstring(L, "AAAA");lua_settable(L, 3);// p2[2] = 'BBBB'lua_pushinteger(L, 2);lua_pushstring(L, "BBBB");lua_settable(L, 3);// p2[3] = 'CCCC'lua_pushinteger(L, 3);lua_pushstring(L, "CCCC");lua_settable(L, 3);// t[2] = p2lua_settable(L, 1);//=========================lua_setglobal(L, t);      // 设置全局变量}/*createLuaTable2(L, "aaa"); 等价于Lua代码:-- 全局变量aaa = {{100,200,300},{"AAAA", "BBBB", "CCCC"}};*/

0 0
原创粉丝点击