Skip to content

Instantly share code, notes, and snippets.

@kpmiller
Last active July 22, 2022 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kpmiller/e5ffbcf05a191ac32efa to your computer and use it in GitHub Desktop.
Save kpmiller/e5ffbcf05a191ac32efa to your computer and use it in GitHub Desktop.
C program to show execution from luaL_loadbuffer, tested with lua 5.3.1
//compiling on OSX 10.11
//export LUA=path/to/lua-5.3.1/src
//cc -I $LUA -L $LUA -l lua -o testlua testlua.c
#include <stdio.h>
#include <string.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
char *luacode =
"io.write(\"Hello from Lua\\n\");\n"
;
int main(int argc, char *argv[])
{
lua_State *L = luaL_newstate();
luaL_openlibs(L);
int err = luaL_loadbuffer(L, luacode, strlen(luacode), "testscript");
if (err)
{
fprintf(stderr, "%s", lua_tostring(L, -1));
lua_pop(L, 1); /* pop error message from the stack */
}
lua_pcall(L, 0, 0, 0);
lua_close (L);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment