Re: LuaL_loadbuffer doesn't appear to use name parameter for error messages

  • From: Sam Putman <atmanistan@xxxxxxxxx>
  • To: LuaJIT <luajit@xxxxxxxxxxxxx>
  • Date: Sat, 11 May 2019 13:07:23 +0200

On Fri, May 10, 2019 at 11:08 PM Peter Cawley <corsix@xxxxxxxxxx> wrote:

The name parameter counts as debug information. If you strip the debug
information from your bytecode, then the name parameter will be used.
Otherwise, the name - along with all other debug information - is persisted
into the bytecode and subsequently re-loaded from the bytecode.



Thanks, this was the prompt I needed to figure out what was going on.

For the sake of others who may encounter this difficulty:

bytecode generated with `string.load(fn)` (note the lack of a second
parameter) and loaded with LuaL_loadbuffer will ignore the value of `*name`
and give it a generic [string "..."] name instead.

if instead one uses `string.load(fn, "")`, the string contents doesn't
matter
because LuaL_loadbuffer will use whatever string one passes it in `*name`.

for completeness: if the bytecode is generated with `luajit -bg`, then the
relative filename is attached and used instead of the `*name` parameter,
while if one uses `luajit -b`, then the `*name` parameter is used!

I'm not sure why it works this way, and two of these seem to fly in the face
of the documentation for `LuaL_loadbuffer`, which merely states:

name is the chunk name, used for debug information and error messages.

But there you have it.

Thanks,
-Sam

Other related posts: