2

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.

5
  • Possible duplicate of Compile Lua from source and create C module with it Commented Nov 26, 2017 at 7:42
  • 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) Commented Nov 26, 2017 at 8:39
  • 1
    Curious: How is Lua running in your app when "not using the Lua interpreter in any way, shape, or form" ? Commented Nov 27, 2017 at 11:16
  • @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. Commented Dec 5, 2017 at 11:39
  • I used the lua c api, and did not use the interpreter that comes as a executable with my installation of lua Commented Dec 5, 2017 at 13:10

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.