lua-aot-5.4 icon indicating copy to clipboard operation
lua-aot-5.4 copied to clipboard

files with shebang fail to run

Open Frityet opened this issue 1 year ago • 6 comments

file:

#!/usr/bin/env lua

print "Hello"

Will fail at runtime, with syntax error in bundled source code.. Using #18 I can see the error is

[string "AOT Compiled module "test""]:1: unexpected symbol near '#'.

Removing the shebang fixes the issue.

Frityet avatar Jul 04 '24 23:07 Frityet

Why is LUAOT_MODULE_SOURCE_CODE not precompiled with luac? It would fix the issue, unless theres a good reason its omitted. Im gonna try to see what precompiling would do...

Frityet avatar Jul 04 '24 23:07 Frityet

Works great, slightly bigger binaries though (~10k?)

Frityet avatar Jul 05 '24 00:07 Frityet

Why is LUAOT_MODULE_SOURCE_CODE not precompiled with luac?

No particular reason. Keeping it as Lua source was easy to implement.

hugomg avatar Jul 05 '24 00:07 hugomg

Why is LUAOT_MODULE_SOURCE_CODE not precompiled with luac?

No particular reason. Keeping it as Lua source was easy to implement.

is keeping the lua source within the binary necessary? im not too familiar with how it works, but wouldnt you have a much smaller binary without it?

Frityet avatar Jul 05 '24 19:07 Frityet

Lua has two kinds of function under the hood: C closures, and Lua closures. Counterintuitively, the luaaot functions are actually Lua closures. The easiest way to build those Lua Closure objects is to use loadstring to compile from source, or from bytecode.

hugomg avatar Jul 05 '24 20:07 hugomg

Oh I see, thats intresting!

Frityet avatar Jul 05 '24 21:07 Frityet