Skip to content

Instantly share code, notes, and snippets.

@tylerneylon
Last active September 4, 2017 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerneylon/4b59c201f6c475f97fda2646cd9bef36 to your computer and use it in GitHub Desktop.
Save tylerneylon/4b59c201f6c475f97fda2646cd9bef36 to your computer and use it in GitHub Desktop.
A bare-bones Lua interpreter, in C.
// 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