Last active
August 29, 2015 14:06
-
-
Save fur-q/e7f745a5a99ebb72c1ed to your computer and use it in GitHub Desktop.
im da bes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <lua.h> | |
#include <lualib.h> | |
#include <lauxlib.h> | |
#define DIE(e) do { fprintf(stderr, "FATAL: %s\n", e); return 1; } while (0) | |
static int l_require(lua_State * L, const char * k) { | |
lua_getglobal(L, "require"); | |
lua_pushstring(L, k); | |
if (lua_pcall(L, 1, 1, 1)) { | |
return 1; | |
} | |
return 0; | |
} | |
static int l_traceback(lua_State * L) { | |
const char * msg = lua_tostring(L, 1); | |
if (!msg) | |
return 0; | |
luaL_traceback(L, L, msg, 1); | |
return 1; | |
} | |
int main(int argc, const char ** argv) { | |
lua_State * L = luaL_newstate(); | |
if (!L) | |
DIE("Error creating Lua state"); | |
luaL_openlibs(L); | |
lua_pushcfunction(L, l_traceback); | |
if (l_require(L, "myscript")) | |
DIE(lua_tostring(L, -1)); | |
lua_close(L); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = gcc | |
LUA = luajit | |
loader: loader.o myscript.l.o | |
$(CC) $(LDFLAGS) -o $@ $^ | |
%.l.o: %.lua | |
$(LUA) -bg $^ $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment