34 lines
644 B
C
34 lines
644 B
C
#include <luajit-2.1/lua.h>
|
|
#include <luajit-2.1/lauxlib.h>
|
|
#include <luajit-2.1/lualib.h>
|
|
#include <luajit-2.1/luajit.h>
|
|
#include <assert.h>
|
|
|
|
#define lua_check(x) if(x != LUA_OK) printf("ERR: %s\n", lua_tostring(L, -1))
|
|
|
|
#define LUA_ARGS lua_State* L
|
|
#define arg(type) lua_to##type(L, 1)
|
|
|
|
int logfn(LUA_ARGS) {
|
|
const char* value = arg(string);
|
|
|
|
printf("[LOG] %s\n", value);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main() {
|
|
lua_State* L = luaL_newstate();
|
|
assert(L != NULL);
|
|
luaL_openlibs(L);
|
|
|
|
lua_pushcfunction(L, logfn);
|
|
lua_setglobal(L, "log");
|
|
|
|
lua_check(luaL_dofile(L, "test.lua"));
|
|
|
|
void* data = lua_newuserdata(L);
|
|
|
|
}
|
|
|