Trying to implement a YouTube example
Last active
August 29, 2015 14:00
-
-
Save sebgod/18d6c5d3e894ca72fd64 to your computer and use it in GitHub Desktop.
Test Lua from C, https://www.youtube.com/watch?v=ZysdYWuPwJU
This file contains 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
*.o | |
test_lua |
This file contains 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
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 |
This file contains 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
foo = function() | |
print("Hello World from Lua!") | |
end |
This file contains 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 <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