Hi Folks,
I'ld like to extend Lua (with a new module), with an existing C codes. I'm using Lua 5.2 on Linux.
Here is how I try:
==%==
luamodule.c:
-------------------
#include "lua.h"
#include "luaconf.h"
#include "lauxlib.h"
#include "example1.h" // contains variable and function declarations
static int _wrap_get_str (lua_State *L) {
const char *s = luaL_checkstring(L, 1);
char retstr[1024];
get_str(s, retstr);
printf("retstr: '%s'\n", retstr);
return 0;
}
void luaopen_example2(lua_State *L) {
static const struct luaL_Reg example2[] = {
{ "get_str", _wrap_get_str },
{ NULL, NULL }
};
luaL_newlib(L, example2);
lua_setglobal(L, "example2");
}
==%==
gcc -g -Wall -shared -fPIC example1.c luamodule.c -o example2.so -I/usr/include/lua5.2 -llua5.2 -lm -ldl