MisterDA / love-release

:love_letter: Lua script that makes LÖVE game release easier
MIT License
451 stars 27 forks source link

Use luajit instead of lua with luarocks #25

Closed MisterDA closed 5 years ago

MisterDA commented 9 years ago

I'm rewriting love-release in pure Lua, and I'd like to add an option to pre-compile the lua files in luajit bytecode. Luajit overrides loadfile and string.dump functions to compile files into its bytecode and not into standard Lua byte code. My main.lua (renamed to love-release when installed) begins with #!/usr/bin/env lua, which is pointless because luarocks launches it with:

#!/bin/sh

exec '/usr/bin/lua5.1' -e 'package.path="/home/antonin/.luarocks/share/lua/5.1/?.lua;/home/antonin/.luarocks/share/lua/5.1/?/init.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;"..package.path; package.cpath="/home/antonin/.luarocks/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/?.so;"..package.cpath' -e 'local k,l,_=pcall(require,"luarocks.loader") _=k and l.add_context("love-release","git-0")' '/usr/local/lib/luarocks/rocks/love-release/git-0/bin/love-release' "$@"

Do you see an easy way to tell luarocks to use luajit instead of lua ? (dev branch)

pablomayobre commented 9 years ago

Well you install luarocks to use luajit instead of Lua

MisterDA commented 9 years ago

Yes but what if I want to use the luarocks that is packaged with my distribution ? I don't want to force the end-user to reinstall luarocks or to use a custom luarocks. For now I use the lua interpreter :

-- luajit :
zip_arc:add(file, "string", string.dump(loadfile(file)))
-- lua :
zip_arc:add(file, "string", bytecode(file))

function bytecode(file)
  local handle = io.popen('luajit -b '..file..' -')
  local result = handle:read("*a")
  handle:close()
  return result
end
Alloyed commented 9 years ago

You can't actually specifically depend on luajit for your script yet, for some reason the piece of code that would allow that is commented out: https://github.com/Alloyed/luarocks/commit/dfce4837addfe258566b6e48dd28a9e7c72bbf62 you can just use the same check the luarocks would've used to see if the user happened to use luajit, though

if package.loaded.jit then do_luajit_stuff() else do_lua_stuff() end
MisterDA commented 9 years ago

Thank you ! It's strange this hasn't been allowed.

pablomayobre commented 7 years ago

For love-release it shouldn't be mandatory to depend on the same version of Lua than LÖVE's, it would be mandatory though for a future case escenario where love-release + loverocks get to compile binary modules ( #41 ), since they are dynamically (desktop) or statically (mobile) linked to lua51.dll