有example.lua文件如下:
EventTable =
{
x = 100;
y = 200;
z = 200;
}
#include <iostream>
using namespace std;
int main()
{
lua_State* pLuaState = lua_open();
int iRet = lua_dofile(pLuaState,"F:\\MySelfPrograms\\LUAv5_Applications\\LuaScripts.lua");
if (iRet)
return 0;
lua_getglobal(pLuaState,"EventTable");
lua_pushnil(pLuaState);
while (lua_next(pLuaState,1))
{
cout << "****弹出前:****" << endl;
int iTop = lua_gettop(pLuaState);
for (int i=iTop;i>=1;--i)
{
cout << i << ":\t" << lua_typename(pLuaState,lua_type(pLuaState,i)) <<endl;
}
cout << "****弹出后:****" << endl;
lua_pop(pLuaState,1);
iTop = lua_gettop(pLuaState);
for (int i=iTop;i>=1;--i)
{
cout << i << ":\t" << lua_typename(pLuaState,lua_type(pLuaState,i)) <<endl;
}
}
lua_close(pLuaState);
::system("pause");
return 0;
}