Last active
July 22, 2022 01:41
-
-
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
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
//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