level 1
贴吧用户_0taSZDa
楼主
还有怎么在Lua中调用c++中的函数 谢谢
#include "stdafx.h"
#include "lua.hpp"
#pragma comment(lib,"Lua.lib")
int _tmain(int argc, _TCHAR* argv[])
{
lua_State *l = luaL_newstate();
luaL_openlibs(l);
luaL_dofile(l, "main.lua");
lua_close(l);
return 0;
}
上面是我在网上找的测试源码 搞了好久才搞清楚是头文件引用的问题
但我现在想在里面加入脚本和程序函数之间互相调用的功能
例如在C++代码中添加一个函数
int Add(int a,int b)
{
return a+b
}
然后在main.lua中调用Add函数 应该怎么做
希望大神给个例子
2015年10月22日 10点10分
1
#include "stdafx.h"
#include "lua.hpp"
#pragma comment(lib,"Lua.lib")
int _tmain(int argc, _TCHAR* argv[])
{
lua_State *l = luaL_newstate();
luaL_openlibs(l);
luaL_dofile(l, "main.lua");
lua_close(l);
return 0;
}
上面是我在网上找的测试源码 搞了好久才搞清楚是头文件引用的问题
但我现在想在里面加入脚本和程序函数之间互相调用的功能
例如在C++代码中添加一个函数
int Add(int a,int b)
{
return a+b
}
然后在main.lua中调用Add函数 应该怎么做
希望大神给个例子