Skip to content

Instantly share code, notes, and snippets.

@IgorYunusov
Forked from kpmiller/testlua.c
Created March 10, 2019 18:51
Show Gist options
  • Save IgorYunusov/2d50fa33418236675b9fa8fcad281ebc to your computer and use it in GitHub Desktop.
Save IgorYunusov/2d50fa33418236675b9fa8fcad281ebc 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