Lua version

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Mercurialol
Prole
Posts: 13
Joined: Fri Apr 18, 2014 3:14 pm

Lua version

Post by Mercurialol » Thu May 15, 2014 4:52 pm

Hey, I was trying to use bit32, but I'm getting attempt to index global 'bit32' (a nil value). I ran 'lua -v', and it returns 'Lua 5.2.3', so I'm guessing that's not the lua version that Love is using. How to find out the actual lua version? Does it mean I'll have to use third party libs for bitwise operations?

Mercurial

foo0
Prole
Posts: 35
Joined: Sun Apr 27, 2014 10:25 am

Re: Lua version

Post by foo0 » Thu May 15, 2014 5:32 pm

At the moment LOVE is using LuaJIT 2.0.3 which corresponds to Lua 5.1. 'bit32' is Lua 5.2 specific I guess. You can use 'bit' instead, which is LuaJIT specific.

How to check Lua version example:

Code: Select all

function luaInfo()
	local info = "Lua version: " .. _VERSION .. "\n"
	info = info .. "LuaJIT version: "

	if (jit) then
		info = info .. jit.version
	else
		info = info .. "this is not LuaJIT"
	end

	return info
end

print(luaInfo())

Mercurialol
Prole
Posts: 13
Joined: Fri Apr 18, 2014 3:14 pm

Re: Lua version

Post by Mercurialol » Fri May 16, 2014 7:22 am

Thanks. Setting up 'bit' doesn't look like that simple.

Edit: I've been trying to follow install instructions on the official website. A little bit of help would be appreciated. I downloaded the lua 5.1.5. source and LuaBitOp-1.0.2

cd LuaBitOp-1.0.2
make macosx

Code: Select all

/Applications/Xcode.app/Contents/Developer/usr/bin/make all "SOCC=MACOSX_DEPLOYMENT_TARGET=10.4 gcc -dynamiclib -single_module -undefined dynamic_lookup"
MACOSX_DEPLOYMENT_TARGET=10.4 gcc -dynamiclib -single_module -undefined dynamic_lookup -fPIC  -o bit.so bit.o
sudo make install

Code: Select all

install -p bit.so `lua installpath.lua bit`
1. Copy the file bit.c from the Lua BitOp distribution to your Lua source code directory. - Check
2. Add this file to your build script (e.g. modify the Makefile) or import it as a build dependency in your IDE. - I'm not sure on where exactly should I add this in the Makefile

3. Edit lualib.h and add the following two lines: '#define LUA_BITLIBNAME "bit" LUALIB_API int luaopen_bit(lua_State *L);' - Check

4. Edit linit.c and add this immediately before the line with {NULL, NULL}: {LUA_BITLIBNAME, luaopen_bit}, - Check

5. Now recompile and you're done!

Recompiling lua gives:

Code: Select all

gcc -o lua  lua.o liblua.a -lm -lreadline
Undefined symbols for architecture x86_64:
  "_luaopen_bit", referenced from:
      _luaL_openlibs in liblua.a(linit.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lua] Error 1
make[1]: *** [macosx] Error 2
make: *** [macosx] Error 2
which looks to me that the makefile doesn't know about the bit.c file(obviously, it hasn't been added to Makefile).

Mercurial

User avatar
slime
Solid Snayke
Posts: 2851
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Lua version

Post by slime » Fri May 16, 2014 2:21 pm

You don't need to download or compile anything. LuaJIT (and thus the BitOp library) is included with LÖVE. When you run a love game through your copy of LÖVE, it uses the LuaJIT library distributed with LÖVE (in the case of Mac OS X, all of the libraries LÖVE uses are in love.app/Contents/Frameworks).

Just run this code with your copy of LÖVE, rather than through a Lua version you downloaded:

Code: Select all

assert(jit and jit.version)

local bit = require("bit")
assert(bit.lshift(1, 4) == 0x10)

Mercurialol
Prole
Posts: 13
Joined: Fri Apr 18, 2014 3:14 pm

Re: Lua version

Post by Mercurialol » Fri May 16, 2014 5:37 pm

Slime: Wow, you're right! I didn't see any mention of this on wiki, though.

Thanks

Post Reply

Who is online

Users browsing this forum: Whitecurse and 11 guests