Upgrading Lua Debug

From PMDOWiki

This page documents the steps to take to get lua debugging to work for PMDO, as a source code level developer. This means building out all the necessary libraries and dependencies for the correct platforms.

If you are a modder and just want to activate this feature, refer to the Tutorial

Components:


NLua and KeraLua

This is a project within PMDO's solution. It's currently forked to a development build instead of using a nuget package. This allows us to specify the lua54 binaries to include in PMDC/PMDC/runtimes This will need to be updated if lua updates and we have reason to update.

Lua

This is a development branch of the lua binaries with a fix to DLOpen. This PR was not accepted into NLua's lua repo so we had to build it ourselves. This will need to be updated if lua updates and we have reason to update.

Build instructions are actually in KeraLua/build/targets, in each platform's vcproject. However they only activate on the respective OS they compile for. You will need to uncomment the respective line in KeraLua.net.6.0.csproj matching your os:

  <!--Import Project="..\targets\BuildLua.Windows.targets" /-->
  <!--Import Project="..\targets\BuildLua.OSX.targets" /-->
  <!--Import Project="..\targets\BuildLua.Linux.targets" /-->

Build the project and it will build the lua binaries. The output should tell you where they are released to. It should also include the lua executable. They seem to require cmake.

Here in windows, the output has been transferred to lua32 and lua64 respectively.

For linux

You can also just follow the exact commands in that csproj file to do the cmake if you dont want to mess with any vs stuff

after creating the lua installation, you should have the following directories:

  • include (always there)
  • lib64 (newly added, holds libraries for linking)
  • bin64 (newly added, holds the lua interpreter)

HOWEVER,

  • the lua static lib must have been generated using -fPIC beforehand
  • you do this by using export CFLAGS="-m64 -fPIC" instead of export CFLAGS=-m64

then follow the instructions from the csproj as normal

you will create a liblua54.so in lib64


luasocket

This is the vanilla luasocket module with a C component that needs to be built for the OS you're currently on. For windows, this is done by opening the sln and building just the socket project in Release mode for x86 and x64. This will need to be updated with lua updates. Maybe. We'll have to see if a new version gets planned for a new lua lib. And also if it'll just work for the old one.

  • To build, you will need Windows SDK 8.1. Otherwise it will complain about toolset missing.
  • You will also need to include lua library headers in the header paths, and the lua libs folder for libs. Or else you will get header not found errors and linker errors.
  • One issue spotted with VC++ compilation in particular is that the stddef.h could not be found, because windows macros were incorrectly set up. I had to add C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ manually to the project ot point it to the right .h file. Same with the libs.


For linux

use luarocks

create a new directory, I named it luarocks
install luarocks here

wget https://luarocks.org/releases/luarocks-3.9.2.tar.gz
tar zxpf luarocks-3.9.2.tar.gz
 
#yes, a second one
mkdir luarocks
cd luarocks-3.9.2
 
#we will configure our install to specifically point to the lua we just created so we don't mess with anything computer-wide
 
./configure --with-lua=/home/user/Documents/lua --with-lua-include=/home/user/Documents/lua/include --with-lua-lib=/home/user/Documents/lua/lib64 --prefix=/home/user/Documents/luarocks/luarocks

then,

make && sudo make install

go up one level and go into luarocks, go into bin subdir

sudo ./luarocks install luasocket

once installation is done, go into ../share/socket.  I need the core.so

THE ABOVE DOESNT WORK BECAUSE IT GENERATES A DYNAMICALY LINKED CORE.SO WITH LUA FUNCTIONS DECLARED BUT NOT DEFINED (use nm core.so to see them)

instead... go to the luasocket directory

edit the src/makefile to use version 5.4, and change the paths

 
-LUAV?=5.1
+LUAV?=5.4
 
-LUAINC_linux_base?=/usr/include
-LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV) $(LUAINC_linux_base)/lua$(LUAV)
-LUAPREFIX_linux?=/usr/local
-CDIR_linux?=lib/lua/$(LUAV)
-LDIR_linux?=share/lua/$(LUAV)
+LUAINC_linux?=/home/user/Documents/lua/include
+LUAPREFIX_linux?=/home/user/Documents/lua/bin
+CDIR_linux?=/home/user/Documents/luasocket/lib
+LDIR_linux?=/home/user/Documents/luasocket/share

run make

but then go into src to perform the last compile step yourself

copy liblua54_static.a to this directory and run


gcc luasocket.o timeout.o buffer.o io.o auxiliar.o compat.o options.o inet.o usocket.o except.o select.o tcp.o udp.o -L. -llua54_static -O -shared -fPIC -ocore.so


mobdebug

This is a single lua file for debugging with sockets. Just update this when lua updates, for safety.

zbrane

You just need to download this separately. The zip will do just fine. Follow the instructions and then start the game. You should see breakpoints hit. https://studio.zerobrane.com/doc-remote-debugging