Skip to content

Instantly share code, notes, and snippets.

@sebgod
Last active August 29, 2015 14:00
Show Gist options
  • Save sebgod/18d6c5d3e894ca72fd64 to your computer and use it in GitHub Desktop.
Save sebgod/18d6c5d3e894ca72fd64 to your computer and use it in GitHub Desktop.
*.o
test_lua
CFLAGS :=
LDFLAGS := `pkg-config --libs lua`
CC=gcc
.PHONY: run
run: test_lua test.lua
./test_lua
test_lua: test_lua.c
$(CC) -c $< $(CFLAGS)
$(CC) -o $@ $(LDFLAGS) $@.o
foo = function()
print("Hello World from Lua!")
end
#include <stdlib.h>
#include <lua.h>
#include <lauxlib.h>
int main(int argc, char *argv[])
{
lua_State *L = luaL_newstate();
// import all global libs into scope
luaL_openlibs(L);
// interpret the file below
luaL_dofile(L, "test.lua");
lua_getglobal(L, "foo");
lua_pcall(L, 0, 0, 0);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment