Cuberite Forum
Linux shared library for Lua - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: Linux shared library for Lua (/thread-1273.html)



Linux shared library for Lua - xoft - 12-02-2013

I need someone who's more experienced in Linux than me.

I'd like to try making MCServer use the Lua library as a shared object, instead of linking it statically. However, I have no idea:
1, How to install the shared library
2, How to find the library's name

I have installed luarocks, which uses Lua and most definitely has the lua shared library somewhere, but how do I find it?

Thanks in advance.


RE: Linux shared library for Lua - SamJBarney - 12-02-2013

LuaRocks itself does not have a lua shared library packaged with it. Instead, it just uses the Lua CLI.

If you are looking for the lua library on a linux machine, you could simply do the following from the command line:
Code:
cd /usr
find . "lua" | grep "lua"
Its not the most efficient way to find it, but that should give you the name of every file in the usr folder which is relavant to lua. And then you just pick through and find any ".so" or ".a" files.

If you can only find .a files, then there isn't a shared library available for lua.


RE: Linux shared library for Lua - xoft - 12-02-2013

I have found out how luarocks work on linux in the meantime - the luarocks' shared libraries use symbols exported from the lua executable itself. The problem for MCServer is that it doesn't export those lua symbols by default, and the only way I found to export the lua symbols is to export *all* symbols. That, however, makes the executable quite large, among other things. Anyone know of a better solution? I need something like __declspec(dllexport) in MSVC; I've tried the __attribute__((visibility("default"))) but it doesn't seem to work.


RE: Linux shared library for Lua - SamJBarney - 12-03-2013

I must be using a different version of luarocks than you, because there are no shared libs in the download I got. It just has scripts in it. Do you have a link to the version you are using?


RE: Linux shared library for Lua - xoft - 12-03-2013

I used the default luarocks in my ubuntu distro, "apt-get install luarocks".
Then I proceeded to install luasocket through luarocks: "luarocks install luasocket".
This compiled the C support libraries for luasocket into a shared library "/usr/local/lib/lua/5.1/socket/core.so". I verified this by running "gdb lua", running the lua interpreter, issuing the "require 'socket'" command, Ctrl+C and back in gdb "info sharedlibrary".
The core.so library is linked so that it contains unresolved symbols from the lua runtime, then whatever executable loads that .so, the loader looks for those lua runtime functions in the executable and binds them to the .so.


RE: Linux shared library for Lua - SamJBarney - 12-03-2013

ok. That makes more sense. So its luasocket that has the .so, not luarocks.


RE: Linux shared library for Lua - xoft - 12-03-2013

New question for the unix folks:
Does linking with the "-rdynamic" flag have any adverse effects, either to code speed, executable size or anything else, besides the point of exporting all functions (which is what we'd like)?

Special extra for the MacOS folks: is that option available in your build toolchain, too?

I can't find much on the issue since google decided to be people-friendly and treats "-rdynamic" the same as "dynamic" Sad


RE: Linux shared library for Lua - NiLSPACE - 12-03-2013

I think you can use "-" to exclude things from the search. For example: "rdynamic -dynamic gcc"

I think you can even work with quotes.


RE: Linux shared library for Lua - SamJBarney - 12-03-2013

"rdynamic" is available on Mac OSX