将lua中的值放入栈顶
发布时间:2020-12-14 22:19:13 所属栏目:大数据 来源:网络整理
导读://将表内的值或普通值放入栈顶void popval(lua_State *L,string val){int pos=0,oldpos=0;if((pos=val.find('.',pos))!=string::npos){string ptr(val,pos-oldpos);lua_getglobal(L,ptr.c_str());pos++;oldpos = pos;}else{lua_getglobal(L,val.c_str());ret
//将表内的值或普通值放入栈顶 void popval(lua_State *L,string val) { int pos=0,oldpos=0; if((pos=val.find('.',pos))!=string::npos) { string ptr(val,pos-oldpos); lua_getglobal(L,ptr.c_str()); pos++; oldpos = pos; } else { lua_getglobal(L,val.c_str()); return; } while((pos=val.find('.',oldpos,pos-oldpos); lua_pushstring(L,ptr.c_str()); lua_gettable(L,-2); pos++; oldpos = pos; } string ptr(val,val.size()-oldpos); lua_pushstring(L,ptr.c_str()); lua_gettable(L,-2); } 用法: popval(L,"normal_num"); int nv = lua_tonumber(L,-1); popval(L,"t.table_str"); string str = lua_tostring(L,-1); 其中测试用lua脚本: normal_num = 152; t = {table_str = "abctest"}; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |