什么是Lua州?

Sam*_*m H 7 lua function

我需要知道,因为我认为需要知道使用lua_setglobal()创建Lua全局是什么.

Gem*_*i14 11

你想在Lua编程中查看这个页面:第一个例子为了做一个类比,假装C或C++程序在一个小盒子里运行并且可以访问它的函数,变量等等.lua_State基本上是一种在程序执行期间访问Lua"框"中正在发生的事情的方法,并允许您将两种语言粘合在一起.


Nic*_*unt 7

可能有帮助的简短例子......

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
Run Code Online (Sandbox Code Playgroud)