lua-users home
lua-l archive

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

On Sat, Jul 6, 2019 at 6:03 PM Benjamin TERRIER <> wrote:
> For instance `lua_dobuffer()` has been removed and the replacement is
> to use `luaL_loadbuffer()` which accepts both text and binary.
> I have not found a function that can load/run only binaries. So, I am
> wondering if the parser is more linked into the library (and harder to
> remove) in Lua 5.
> To conclude: is there a guide to remove the parser from Lua 5?
> Is there a better function than `luaL_loadbuffer()` to run binaries?

First, you need to specify the Lua version more precisely, as Lua does
not use semantic versioning and different 5.x versions have
incompatibilities with each other, including breaking C API changes.
5.1 and 5.3 are the most commonly used from my understanding; 5.1 is
officially end-of-life but commonly used for compatibility with LuaJIT
(a third-party project built on 5.1), and 5.3 is the latest stable
version. (5.4 is in alpha right now.) The remainder of this email
assumes you are referring to 5.3.

Let's look at the reference manual for 5.3 [1]:

- `luaL_loadbuffer` is stated to be equivalent to `luaL_loadbufferx`
with mode `NULL`.
- `luaL_loadbufferx` says that it uses `lua_load`, and mode is a
string with the same behavior as in `lua_load`.
- `lua_load` refers to the Lua standard library function `load` for
the use of the mode string.
- Lua `load` function says that mode can be "t" for text chunks only,
"b" for binary chunks only, or "bt" for either.

So for your question, "Is there a better function than
`luaL_loadbuffer()` to run binaries?", the answer is
`luaL_loadbufferx()` with the mode argument set to "b".