Skip to content

Commit

Permalink
compat: use --compile replace --copy option
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozg committed May 11, 2023
1 parent b0bdfdc commit dbe055a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ git init myapp
vim myapp/main.lua
# Run the app
luvi myapp
# Build the binary with compiled Lua code when done
# Build the binary when done
luvi myapp -o mybinary
# Build the binary with compiled, striped Lua code when done
# Build the binary with compiled, striped Lua bytecode when done
luvi myapp -o mybinary -s
# Build the binary just copy Lua code when done
luvi myapp -o mybinary --copy
# Build the binary with compiled Lua bytecode when done
luvi myapp -o mybinary --compile
# Run the new self-contained binary
./mybinary
# Deploy / Publish / Profit!
Expand Down Expand Up @@ -243,9 +243,9 @@ Usage: luvi bundle+ [options] [-- extra args]
--version Show luvi version and compiled in options.
--output target Build a luvi app by zipping the bundle and inserting luvi.
--main path Specify a custom main bundle path (normally main.lua)
--copy Do not compile, just copy Lua code and compress.
--strip Compile Lua code and strip debug info.
--force Force build then bundle, ignore Lua compile error.
--compile Compile Lua code into bytecode before bundling.
--strip Strip debug info from compiled Lua code.
--force Ignore errors when compiling Lua code.
--help Show this help file.
-- All args after this go to the luvi app itself.

Expand Down
8 changes: 4 additions & 4 deletions src/lua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local commands = {
["--version"] = "version",
["-h"] = "help",
["--help"] = "help",
["--copy"] = "copy",
["--compile"] = "compile",
["--force"] = "force",
["-s"] = "strip",
["--strip"] = "strip"
Expand All @@ -68,9 +68,9 @@ Usage: $(LUVI) bundle+ [options] [-- extra args]
--version Show luvi version and compiled in options.
--output target Build a luvi app by zipping the bundle and inserting luvi.
--main path Specify a custom main bundle path (normally main.lua)
--copy Do not compile, just copy Lua code and compress.
--strip Compile Lua code and strip debug info.
--force Force build then bundle, ignore Lua compile error.
--compile Compile Lua code into bytecode before bundling.
--strip Strip debug info from compiled Lua code.
--force Ignore errors when compiling Lua code.
--help Show this help file.
-- All args after this go to the luvi app itself.
Expand Down
7 changes: 4 additions & 3 deletions src/lua/luvibundle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,18 @@ local function buildBundle(options, bundle)
elseif stat.type == "file" then
print(" " .. child)
local ctx = bundle.readfile(child)
local isLua = name:sub(-4, -1) == ".lua"
local isLua = name:sub(-4, -1):lower() == ".lua"
local compile = options.strip or options.compile

-- compile, strip lua code, but skip package.lua
if isLua and name ~= 'package.lua' and not options.copy then
if compile and isLua and name:lower() ~= 'package.lua' then
local fn, err = load(ctx, child)
if not fn and not options.force then
error(err)
else
ctx = string.dump(fn, options.strip)
end
end

writer:add(child, ctx, 9)
end
end
Expand Down

0 comments on commit dbe055a

Please sign in to comment.