2
votes

I have a program written in a combination of c and lua. I know how to compile c programs, and I know how to compile lua programs, but I don't know how I can compile a hybrid program into a single executable. It's also important to note that I'm using the lua c api.

EDIT: just to clarify, I'm not using the lua interpreter in anyway shape or form.

1
This is not a duplcate, This question is about embedding a Lua scrpt in a C executable, the question Ring Ø pointed to is about embedding the Lua interpreter in a C executable (which the OP may or may not want to do) - Remo.D
Curious: How is Lua running in your app when "not using the Lua interpreter in any way, shape, or form" ? - tonypdmtr
@tonypdmtr I guess the OP will either embed the Lua interpreter by statically link it or may decide to rely on shared libraries (.dll or .so). He probably means that he's not using the lua executable that comes with the Lua distribution. - Remo.D
I used the lua c api, and did not use the interpreter that comes as a executable with my installation of lua - Ace shinigami

1 Answers

3
votes

I thing the easiest way would be to store you program a string and then use the luaL_dostring() function to execute it.

I did not check but I'm pretty sure you can compile the Lua code with luac and store it in a char [] buffer instead of storing the script source code. This will speed up things a bit by doing the compilation of the source code to Lua VM bytecode once for all at compile time (rather than at runtime).

Something like:

const char *luacode = "print('Hello')";
lua_State *L;
...
...

   luaL_dostring (L, luacode);