一个简单的lua插件示例(lua5.2版本)
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
/* 库 open 函数的前置声明 */
int luaopen_mt(lua_State *L);
/* Function mt_get_device_name
* @return string device name
*/
static int mt_get_device_name(lua_State *L)
{
lua_pushstring(L, "66666");
return 1;
}
//注册函数库
static const luaL_Reg mt_lib[] = {
{"device_name", mt_get_device_name}, //获取设备名称
{NULL, NULL}};
int luaopen_mt(lua_State *L)
{
luaL_newlib(L, mt_lib);
return 1;
}
ubuntu进入windows目录cd /mnt/e
在64位linux下编译3so:
gcc -c -fPIC -o mt.o mt.c -m32
gcc -m32 -shared -o mt.so mt.o
// -m32表示编译为32位的程序,不需要刻意不用写 -m32
然后就可以开心的用啦,啦啦啦啦啦