开发者

What is a Lua State?

I need to know becau开发者_如何学Pythonse I supposedly need to know what it is to make a Lua global using lua_setglobal().


You'll want to check out this page in Programming in Lua: A first example To make an analogy, pretend that the C or C++ program is running in a little box and has access to its functions, variables, and so on. The lua_State is basically a way to access what's going on in the Lua "box" during execution of your program and allows you to glue the two languages together.


Brief example which may help...

lua_State* L=lua_open();           // create a Lua state
luaL_openlibs(L);                  // load standard libs 

lua_pushstring(L, "nick");         // push a string on the stack
lua_setglobal(L, "name");          // set the string to the global 'name'

luaL_loadstring(L, "print(name)"); // load a script
lua_pcall(L, 0, 0, 0);             // call the script
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜