DOOM mark_lee

一旦让我开始,我就不会停止

lua call c/c++ function

this article is tenchnique reminder

key point:

1. c/c++ DLL

2. below mylib as exported name required and called from lua script, should be same

extern "C"

{

#include "lua.h"

#include "lualib.h"

#include "lauxlib.h"

 

int lhsadd(lua_State *L)

{

return 1;
}

 

int lhssubs(lua_State *L)

{

return 1;
}

static luaL_Reg libs[] = {{"lhsadd",lhsadd},{"lhssubs",lhssubs},{NULL,NULL}};

 

 

__declspec(dllexport) in luaopen_mylib(lua_State *L)

{

const char* libname = "mylib2";

luaL_register(L,libname,libs);

return 1;

}

 

}

 

 

.lua testing script

require "mylib"

print(mylib2.lhsadd(1.1,2.2))

print(mylib2.lhsadd(2.2,1.1))

 

 

 

 

 

 

 

 

阅读更多
个人分类: lua
想对作者说点什么? 我来说一句

lua and acl example

2018年02月06日 30.97MB 下载

没有更多推荐了,返回首页

不良信息举报

lua call c/c++ function

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭