Re: [ANN] lcm -- Lua Code Melder, 2026-04
"'Martin Eden' via lua-l" <[email protected]> Fri, 24 Apr 2026 08:54:23 +0200
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
On 2026-04-24 01:16, mjmouse9999 wrote:
> On Friday, April 24, 2026 at 3:22 am UTC+10 Martin Eden wrote:
>> Hello list,
>>
>> I've updated lcm, Lua Code Melder.
>>
>> It's command-line tool to merge all .lua files in provided directory
>> into one Lua code block.
>>
>> https://github.com/martin-eden/lua_code_melder
> This bit of the implementation is interesting:
>
> local add_module =
> function(module_name, module_code_str)
> local compiled_code = assert(load(module_code_str, module_name, 't'))
>
> _G.package.preload[module_name] =
> function(...)
> return compiled_code(...)
> end
> end
>
> for module_name, module_code_str in pairs(Modules) do
> add_module(module_name, module_code_str)
> end
>
> I did make a combiner for the main Teal module to generate tl.lua, but it
> instead just fills out package.preload directly, rather than doing separate
> load(...) calls. It also scans the dependencies by looking for require
> statements
> (This is helped by the fact that Teal always includes the brackets)
>
> It instead just does the following for each module in the output file:
>
> -- module this from this.lua
> package.preload["this"] = function(...)
> -- contents of the this.lua file
> end
>
> https://github.com/teal-language/tl/blob/main/extras/combine.tl
>
> However it looks like your implementation will give correct line numbers for
> errors and tracebacks, which is a very nice thing to have.
>
Hello Mjmouse,
I've tested your approach and like it. Going to use it too.
Thanks for the feedback!
--
Below is my two test scripts. We are testing line numbers
using debug.traceback(). In both cases line numbers are relevant.
But with direct code insertion you have syntax highlighting and
less code lines.
( -- test_direct.lua
_G.package.preload['modules.a.Represent'] =
function(...)
return
function(self)
print(debug.traceback())
print(self.Data)
end
end
_G.package.preload['modules.a'] =
function(...)
local Represent = require('modules.a.Represent')
return
{
Represent = Represent,
Data = '[Test representation.]',
}
end
_G.package.preload.test =
function(...)
local ModuleA = require('modules.a')
ModuleA:Represent()
end
require('test')
)
( -- test_wrapped.lua
local Modules = {
['modules.a'] = [[
local Represent = require('modules.a.Represent')
return
{
Represent = Represent,
Data = '[Test representation.]',
}
]],
['modules.a.Represent'] = [[
return
function(self)
print(debug.traceback())
print(self.Data)
end
]],
test = [[
local ModuleA = require('modules.a')
ModuleA:Represent()
]],
}
do
local add_module =
function(module_name, module_code_str)
local compiled_code = assert(load(module_code_str, module_name, 't'))
_G.package.preload[module_name] =
function(...)
return compiled_code(...)
end
end
for module_name, module_code_str in pairs(Modules) do
add_module(module_name, module_code_str)
end
end
require('test')
)
-- Martin
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/3e185786-784d-4fde-8e5d-34ba7e86ade5%40disroot.org.