bettola/assets/scripts/bin/build.lua

28 lines
791 B
Lua

-- /bin/build - "Compiles" a .lua file into an executable.
local source_filename = arg[1]
if not source_filename then
return "build: missing file operand"
end
-- Check for .lua extension.
if not source_filename:match("%.lua$") then
return "build: input file must be a .lua file"
end
local current_dir = bettola.get_current_dir(context)
local source_node = current_dir.children[source_filename]
if not source_node then
return "build: cannot open '" .. source_filename .."': No such file"
end
if source_node.type ~= 0 then
return "build: '" .. source_filename .. "' is not a regular file"
end
local executable_filename = source_filename:gsub("%.lua$", "")
local source_content = source_node.content
return bettola.create_executable(context, executable_filename, source_content)