Best way to install Lua in Smaugfuss 1.9?

Posted by Lerkista on Fri 19 Sep 2014 06:01 AM — 9 posts, 42,215 views.

#0
Hi, i've downloaded this file: http://www.gammon.com.au/files/smaug/smaug17fuss_lua_v2.tgz

It's for 1.7, so what do i need to do to make it work in 1.9??

Maybe just to copy lua_* files in src and the lua dir to my 1.9 source and try to compile it?? and after put all the call_lua calls in all other functions??

Any who already make it work in 1.9 have any experience to share??

Thankx
Australia Forum Administrator #1
I don't know the answer directly, but if I were attempting this I would first copy all the "new" files (eg. the .lua ones), as clearly they won't be in the Smaug distribution.

Then do a "diff" of the 1.7 version of Smaug to the one in that .tgz file. That would show you what changes I made. With luck they can be applied back into 1.9, possibly even using "patch".
#2
I get this errors:


make -s smaug
o/lua_scripting.o: In function `optboolean':
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:72: undefined reference to `lua_gettop(lua_State*)'
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:76: undefined reference to `lua_type(lua_State*, int)'
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:79: undefined reference to `lua_type(lua_State*, int)'
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:80: undefined reference to `lua_toboolean(lua_State*, int)'
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:82: undefined reference to `luaL_checkinteger(lua_State*, int)'
o/lua_scripting.o: In function `check_vnum':
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:88: undefined reference to `luaL_checkinteger(lua_State*, int)'
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:90: undefined reference to `luaL_error(lua_State*, char const*, ...)'
o/lua_scripting.o: In function `make_char_ud':
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:99: undefined reference to `luaL_error(lua_State*, char const*, ...)'
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:101: undefined reference to `lua_pushlightuserdata(lua_State*, void*)'
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:102: undefined reference to `lua_getfield(lua_State*, int, char const*)'
/home/lerkista/Mud/lua-smaugfuss/src/lua_scripting.c:103: undefined reference to `lua_setmetatable(lua_State*, int)'
...
....
and the error list goes big


Any ideas to fix that??
Australia Forum Administrator #3
Looks like a linking error to me, so perhaps you didn't add:


 -llua


to the linker options.
#4
I use a free shell to run the mud, and it seems they don't have lua installed, so i tried to install myself in my account, it installs fine and everything in ~/usr dir, but i can't make it work with make, so i copy the lib to the mud src and change Makefile with this:

L_FLAGS = $(PROF) $(SOLARIS_LINK) -lz $(NEED_DL) liblua.a -lm

Don't know if this is the problem

EDIT: in fact i unpack smaug1.7 with lua and it compiles fine, using liblua.a, so i copy the lua_* files to my smaug1.9 and just add lua.bits to the Makefile to test, i got this error:


lua_bits.c: In function 'int bit_tonumber(lua_State*)':
lua_bits.c:65: error: invalid conversion from 'const char*' to 'const unsigned char*'
make[1]: *** [o/lua_bits.o] Error 1

so i change this:

  // get text to convert            
  const unsigned char * text = luaL_checkstring (L, 1);
  const unsigned char * p;

to this:

  // get text to convert            
  const char * text = luaL_checkstring (L, 1);
  const char * p;


And this errors appear:


o/lua_bits.o: In function `bit_bnot':
/home/lerkista/Mud/prueba/cagua/src/lua_bits.c:47: undefined reference to `luaL_checknumber(lua_State*, int)'
/home/lerkista/Mud/prueba/cagua/src/lua_bits.c:47: undefined reference to `lua_pushnumber(lua_State*, double)'
o/lua_bits.o: In function `bit_band':
/home/lerkista/Mud/prueba/cagua/src/lua_bits.c:48: undefined reference to `lua_gettop(lua_State*)'
/home/lerkista/Mud/prueba/cagua/src/lua_bits.c:48: undefined reference to `luaL_checknumber(lua_State*, int)'
/home/lerkista/Mud/prueba/cagua/src/lua_bits.c:48: undefined reference to `luaL_checknumber(lua_State*, int)'
...


Maybe is something about the compiler?? smaug1.7 uses gcc and smaug1.9 g++
Amended on Sun 21 Sep 2014 08:32 PM by Nick Gammon
Australia Forum Administrator #5
It still looks like a linking error. Can you run Lua stand-alone?

Just type "lua" at the command line.

You should see something like:


Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
>
#6
Yeah, i can, in both shells i use:

Free shell (running CentOs:

lerkista ~ $ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> 


Cygwin:

Mario@Mario1 ~
$ lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
>
Australia Forum Administrator #7
Yes you were partly right there. I could reproduce your problem. The thing is that Lua used gcc and Smaug used g++.

The only way I could make it work was to recompile Lua.

You can get Lua from:

http://www.lua.org/ftp/lua-5.1.5.tar.gz

I suggest staying away from Lua 5.2 because some of the things I used may have changed in Lua 5.2.

In the lua "src" directory (not the top-level directory) change in the Makefile:


# makefile for building Lua
# see ../INSTALL for installation instructions
# see ../Makefile and luaconf.h for further customization

# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================

# Your platform. See PLATS for possible values.
PLAT= none

CC= gcc
CFLAGS= -O2 -Wall $(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
LIBS= -lm $(MYLIBS)


to:


# makefile for building Lua
# see ../INSTALL for installation instructions
# see ../Makefile and luaconf.h for further customization

# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================

# Your platform. See PLATS for possible values.
PLAT= none

CC= g++
CFLAGS= -O2 -Wall $(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
LIBS= -lm $(MYLIBS)


Changed line in bold. Then do a "make clean" and a "make" (I used "make posix") followed by a "sudo make install". The "make install" needs to be done at the top-level directory, not the "src" one.

Having done that, make sure that -llua is in your L_FLAGS in the Smaug Makefile, eg.


L_FLAGS = $(PROF) $(SOLARIS_LINK) -lz $(NEED_DL) -llua


Then it should link OK.




If you can't install Lua because you don't have rights, just link in the lualib.a file as part of the link step in Smaug.
Amended on Mon 22 Sep 2014 03:06 AM by Nick Gammon
#8
Hi

I tried what you said, and works, i can't make it work with -llua, but if i copy the lib and use liblua.a it compiles fine

I need some time to see if everything works fine

Thanks