level 1
测试12306
楼主
根路径下创建文件 test.lua ,写入内容:
Table = {
people = {
name = "Neil",
age = 18,
},
}
c++代码:
lua_State *L = luaL_newstate();
int bRet = luaL_dofile(L,"test.lua");
lua_getglobal(L,"Table");
// 更改字段的内容
lua_pushstring(L, "Michael");
lua_setfield(L, -2, "name");
//执行打印 查看
lua_getfield(L,-1,"name");
str = lua_tostring(L,-1);
std::cout<<"people : name = "<<str.c_str()<<std::endl;
stackDump(L);
lua_close(L);
打印结果是修改后的值,但是文件test.lua内容未修改.
求教 要怎么才能通过c++修改test.lua的值.
2020年08月18日 06点08分
1
Table = {
people = {
name = "Neil",
age = 18,
},
}
c++代码:
lua_State *L = luaL_newstate();
int bRet = luaL_dofile(L,"test.lua");
lua_getglobal(L,"Table");
// 更改字段的内容
lua_pushstring(L, "Michael");
lua_setfield(L, -2, "name");
//执行打印 查看
lua_getfield(L,-1,"name");
str = lua_tostring(L,-1);
std::cout<<"people : name = "<<str.c_str()<<std::endl;
stackDump(L);
lua_close(L);
打印结果是修改后的值,但是文件test.lua内容未修改.
求教 要怎么才能通过c++修改test.lua的值.