lua-users home
lua-l archive

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


On Tue, Feb 28, 2017 at 3:56 PM, Tony Papadimitriou <> wrote:
> How would one do the equivalent of luaL_dostring() but instead of a null
> terminated C string with source code I want to load the binary output of
> luac compiled code.
> And I want to get this code to be loaded from a C array, not from some
> external file.  Is this possible, and if so, can someone provide an example?

The source Tony, use the source.

Now, seriously. Every luaL_* function is done in term of the
primitives in lua_*. If you look at lauxlib.h you'll find
luaL_do{string,file} are just luaL_loadXX plus lua_pcall. In turn all
luaL_load* end up in luaL_loadbufferx, which just uses lua_load (
that's the primitive one ) which is documented as reading either text
or binary. So binary is fine in load_buffer. As you probably do not
want to mingle with writing a reader function ( as lualib has a
perfectly fine one which it uses to implement the loadbuffers ) you
just need to copy a bit fom luaL_dostring and make yourself a
luaL_dobuffer[x] using loadBufferX and lua_pcall in the same way
luaL_dostring is done. Easy peasy, faster to do than tell.

Francisco Olarte.