Last active
September 4, 2017 03:17
-
-
Save tylerneylon/4b59c201f6c475f97fda2646cd9bef36 to your computer and use it in GitHub Desktop.
A bare-bones Lua interpreter, in C.
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
// A bare-bones Lua interpreter, in C. | |
#include <stdio.h> | |
#include <string.h> | |
#include "lua.h" | |
#include "lauxlib.h" | |
#include "lualib.h" | |
int main() { | |
// Start our Lua run-time state and load the standard libraries. | |
lua_State *L = luaL_newstate(); | |
luaL_openlibs(L); | |
// Read-parse(load)-evaluate(call). In a loop. | |
char buff[2048]; | |
while ((fgets(buff, sizeof(buff), stdin))) { | |
luaL_loadstring(L, buff); | |
lua_pcall(L, 0, 0, 0); | |
} | |
// Clean up the lua run-time state and exit. | |
lua_close(L); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment