开发者

What is a Lua State?

开发者 https://www.devze.com 2023-01-25 05:48 出处:网络
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

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

精彩评论

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