[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Storing Lua code in a C library
- From: steve donovan <steve.j.donovan@...>
- Date: Wed, 23 May 2012 08:33:54 +0200
On Wed, May 23, 2012 at 2:18 AM, Rena <email@example.com> wrote:
> How does lua_load() react if Lua was compiled without the ability to
> compile code? Is there a reliable way to embed Lua code in a C
If you did retain the ability to compile code, then there is another
option which is as portable as you wish it to be.
And that's to embed the source directly in a C file, as a properly
escaped multiline C string, which is then loaded.
const char *code = \
"function boo(x)\n" \
" print(\"hello\",x)\n" \
I did this with winapi, for about a hundred lines of simple utility
functions that would be tedious to code in C. I don't know when one
hits preprocessor limitations, however.
If working with LuaJIT, then there's an option to compile Lua files as
object files containing the bytecode, which can be directly linked
with the project.