Luaplus is the LUA C + + enhancement, which means that Luaplus itself is enhanced by the LUA source. It is a better choice to cooperate with C + +.
The current version of Luaplus is: Luaplus for Lua 5.01 Distribution build 1080 (February 28, 2004). You can go to the http://luaplus.org/site to download:
Source Code (HTTP://WWHIZ.COM/LUAPLUS/LUAPLUS50_BUILD1081.ZIP)
Target Code (HTTP://WWHIZ.COM/LUAPLUS/LUAPLUS50_BUILD1081_WIN32BINARIES.ZIP)
Introduction Luaplus: Easy LUA for C + + extended mu Maple Blog
[Since the LUA kernel was upgraded to 5.1, Luaplus also followed the upgrade.) The latest luaplus can be retrieved via SVN, address svn://svn.luaplus.org/luaplus/work51, and Luaplus's kernel based on 5.0 is still being updated and can be retrieved via SVN, address svn:// Svn.luaplus.org/root/luaplus/dev]
I'll show you how to use luaplus and how to make it more convenient for luaplus to work seamlessly with C + + classes.
1. Call Lua Scripts
// 创建Lua解释器:
LuaStateOwner state;
// 执行Lua脚本:
state->DoString("print('Hello World\\n')");
// 载入Lua脚本文件并执行:
state->DoFile("C:\\test.lua");
// 载入编译后的Lua脚本文件并执行:
state->DoFile("C:\\test.luac");
2. Call each other with LUA scripts
// 为Lua脚本设置变量
state->GetGlobals().SetNumber("myvalue", 123456);
// 获得Lua变量的值
int myvalue = state->GetGlobal("myvalue").GetInteger();
// 调用Lua函数
LuaFunction<int> luaPrint = state->GetGlobal("print");
luaPrint("Hello World\n");
// 让Lua调用C语言函数
int add(int a, int b){ return a+b;}
state->GetGlobals().RegisterDirect("add", add);
state->DoString("print(add(3,4))");
// 让Lua调用C++类成员函数
class Test{public: int add(int a, int b){return a+b;}};
Test test;
state->GetGlobals().RegisterDirect("add", test, &Test::add);
state->DoString("print(add(3,4))");