lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Apr 30, 2014 at 8:58 AM, Igor Trevisan <igt1972@gmail.com> wrote:
> I would like to work with different lua files (text format, no bytecode).
> Is there a way to load and execute from my C program a Lua
> fuction which is "distributed" in more than a Lua text file?
> Without melding the files in a single bytecode?

Yes, this is a common need and there are several ways to solve it.

You can encode the Lua file as a C string and load that; this string
can then be compiled as part of your program.  (The Lua compiler is so
fast that generally compiling-as-bytecode is only needed for the most
performance-sensitive applications and/or embedded)

(Writing a Lua file as a C string is a straightforward exercise in Lua)

The Lua file can be attached to your executable, say as a resource (if
Windows) or simply glued to the end of the executable (which is how
srlua works)

If there are multiple files, they can be collected together as a code
archive (see Squish, soar, and others)