aarzilli / golua

Go bindings for Lua C API - in progress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Building for 5.3

Ambrevar opened this issue · comments

OS: Arch Linux
Lua version: 5.3.4

Building for 5.3 with the go install -tags llua command, I get the following error:

github.com/aarzilli/golua/lua
# github.com/aarzilli/golua/lua
In file included from ./lua.h:16:0,
                 from ./golua.go:6,
                 from $WORK/github.com/aarzilli/golua/lua/_obj/_cgo_export.c:3:
./luaconf.h:192:34: fatal error: lua5.3-deb-multiarch.h: No such file or directory
 #include "lua5.3-deb-multiarch.h"
                                  ^

It works if I comment the deb related lines in luaconf.h:

/* This defines DEB_HOST_MULTIARCH */
// #include "lua5.3-deb-multiarch.h"

#define LUA_ROOT	"/usr/local/"
#define LUA_ROOT2	"/usr/"
#define LUA_LDIR	LUA_ROOT "share/lua/" LUA_VDIR "/"
#define LUA_LDIR2	LUA_ROOT2 "share/lua/" LUA_VDIR "/"
#define LUA_CDIR	LUA_ROOT "lib/lua/" LUA_VDIR "/"
// #define LUA_CDIR2	LUA_ROOT2 "lib/" DEB_HOST_MULTIARCH "/lua/" LUA_VDIR "/"
#define LUA_CDIR3	LUA_ROOT2 "lib/lua/" LUA_VDIR "/"

Compared to the 5.2 branch, there are header files both in lua/ and in lua/lua/. Why is it so? What are the differences?

Why not using the system headers by the way? If I try removing the embedded headers in lua/, I get the following error:

github.com/aarzilli/golua/lua
# github.com/aarzilli/golua/lua
/tmp/go-build411086781/github.com/aarzilli/golua/lua/_obj/lua.cgo2.o: In function `_cgo_1901af7180ba_Cfunc_lua_insert':
./cgo-gcc-prolog:594: undefined reference to `lua_insert'
/tmp/go-build411086781/github.com/aarzilli/golua/lua/_obj/lua.cgo2.o: In function `_cgo_1901af7180ba_Cfunc_lua_remove':
./cgo-gcc-prolog:957: undefined reference to `lua_remove'
/tmp/go-build411086781/github.com/aarzilli/golua/lua/_obj/lua.cgo2.o: In function `_cgo_1901af7180ba_Cfunc_lua_replace':
./cgo-gcc-prolog:971: undefined reference to `lua_replace'
/tmp/go-build411086781/github.com/aarzilli/golua/lua/_obj/c-golua.o: In function `callback_function':
./c-golua.c:77: undefined reference to `lua_remove'
collect2: error: ld returned 1 exit status

Could you enlighten me here?

Could you enlighten me here?

Sure, I copied the headers in the wrong directory and did not notice because it still compiled against the 5.3 library. Take a look at the new commit, see if it works better.

PS. about using the system headers, IIRC they may not be in the include path and the pkg-config name of the library is not guaranteed to be the same on all system.

Thanks, works like a charm!

Also I noticed that you changed the references to lua_insert et al. for lua_rotate. I don't understand why this change is needed (or why the original code generated the aforementioned error) considering that the headers define the following macros:

 #define lua_insert(L,idx)	lua_rotate(L, (idx), 1)

 #define lua_remove(L,idx)	(lua_rotate(L, (idx), -1), lua_pop(L, 1))

 #define lua_replace(L,idx)	(lua_copy(L, -1, (idx)), lua_pop(L, 1))

Finally, why not making 5.3 the default and 5.1 a separate branch?

C macros can't be called in Go.

Did not know that, thanks!

What about my last question?

The downside is that it could break code of people using master expecting it to build against lua5.1. And I don't see what the upside would be.

Upside would be following an up-to-date Lua, we cannot stick to old versions forever...

Upside would be following an up-to-date Lua, we cannot stick to old versions forever...

Renaming a branch doesn't affect this. Also there's luajit.

Making lua5.1 the default is pulling down migration to the latest version in general.

Anyways, a newcomer would expect golua to work on the latest official release of Lua. Why Lua 5.1 and not 5.2 then?

As for luajit, it is not the standard VM: if a user wants to build golua upon luajit, he/she will know that it will require some specialisation (in our case, checking out the dedicated lua5.1 branch).