Feature #906

Create luasql lib and add it to installs

Added by IR4T4 over 3 years ago. Updated over 2 years ago.

Status:Fixed% Done:

100%

Priority:High
Assignee:Spyhawk
Category:Mod QAGAME
Target version:2.75
OS: Arch:

Description

Create luasql bin from lib folder and copy it to <fs_homepath>/legacy/lualibs/luasql/ (or similar)

See this forum thread for some hint about compilation and correct linking.
Also, this might be of interest.


Related issues

Related to ET: Legacy Development - Bug #920: Fix/inspect retrieving cursor objects with LuaSQL Invalid 30.01.2016
Blocks ET: Legacy Development - Feature #403: Add bayesian skill rating Fixed 23.12.2018
Blocks ET: Legacy Development - Task #916: Release 2.75 'Learning to fly' Fixed 09.01.2016

Associated revisions

Revision dbda4d8f
Added by IR4T4 over 3 years ago

misc: hello FEATURE_LUASQL refs #906 (builds fine/untested)

Revision 8bd570fb
Added by Spyhawk about 3 years ago

misc: allow luasql with dynamic linking, refs #906

Revision d20f73b4
Added by Spyhawk over 2 years ago

general: moved LuaSQL internally, refs #906

Revision 049b58ba
Added by Spyhawk over 2 years ago

general: set luasql dependency on qagame, refs #906

Revision 71864bb5
Added by Spyhawk over 2 years ago

general: adjusted luasql path, refs #906

Revision 93d73f50
Added by Spyhawk over 2 years ago

general: fixed LuaSQL static compilation, refs #906

Revision 68851ea9
Added by Spyhawk over 2 years ago

general: also install luasql lib on windows, refs #906

Revision 92b2a796
Added by RaFaL over 2 years ago

cmake: move cgame and ui dlls into legacy directory/fix for building etl_bin.pk3

Revision 12908bff
Added by Spyhawk over 2 years ago

cmake: fix qagame target install on windows, refs #906

Revision 3afe656e
Added by Spyhawk over 2 years ago

cmake: LuaSQL cmake file cleanup, refs #906

Revision 3b02ef4b
Added by Spyhawk over 2 years ago

cmake: adjusted outpupt pathes and cleanup, refs #906

Revision 924c14b9
Added by Spyhawk over 2 years ago

cmake: possible fix for MSVC and shared lib, refs #906

Revision 910befc2
Added by Spyhawk over 2 years ago

cmake: use LuaSQL static compile, refs #906

History

#1 Updated by IR4T4 over 3 years ago

  • Priority changed from Normal to High

#2 Updated by Spyhawk over 3 years ago

#3 Updated by Spyhawk over 3 years ago

  • Description updated (diff)

#4 Updated by IR4T4 over 3 years ago

  • Blocks Task #916: Release 2.75 'Learning to fly' added

#5 Updated by Spyhawk about 3 years ago

  • Description updated (diff)
  • Category changed from Mod generic to Mod QAGAME

#6 Updated by Spyhawk about 3 years ago

  • File test.lua added

Some work has been done, but etlded crashes at startup after loading a lua script (static compil).
Check http://www.lua.org/bugs.html, as the bug listed might be relevant here (although backporting it didn’t solve the issue..).

Backtrace:

Lua 5.3 API: Loading test.lua
]
Program received signal SIGSEGV, Segmentation fault.
0xeaabfb3c in luaH_newkey () from ./legacy/lualibs/luasql/sqlite3.so
(gdb) backtrace
#0 0xeaabfb3c in luaH_newkey () from ./legacy/lualibs/luasql/sqlite3.so
#1 0xeaab4cf8 in lua_rawset () from ./legacy/lualibs/luasql/sqlite3.so
#2 0xeaab293c in cur_fetch (L=0x8ec07d4) at /home/remy/dev/etlegacy/libs/luasql/src/ls_sqlite3.c:195
#3 0xeae44904 in luaD_precall () from ./legacy/qagame.mp.i386.so
#4 0xeae4fb5b in luaV_execute () from ./legacy/qagame.mp.i386.so
#5 0xeae44ce5 in luaD_call () from ./legacy/qagame.mp.i386.so
#6 0xeae44d3b in luaD_callnoyield () from ./legacy/qagame.mp.i386.so
#7 0xeae40f05 in f_call () from ./legacy/qagame.mp.i386.so
#8 0xeae44195 in luaD_rawrunprotected () from ./legacy/qagame.mp.i386.so
#9 0xeae44f87 in luaD_pcall () from ./legacy/qagame.mp.i386.so
#10 0xeae42593 in lua_pcallk () from ./legacy/qagame.mp.i386.so
#11 0xeade42ef in G_LuaCall (vm=0x8e6fe80, func=0xeae75549 "G_LuaStartVM", nargs=0, nresults=0) at /home/remy/dev/etlegacy/src/game/g_lua.c:1828
#12 0xeade8c43 in G_LuaStartVM (vm=0x8e6fe80) at /home/remy/dev/etlegacy/src/game/g_lua.c:2324
#13 0xeade422b in G_LuaInit () at /home/remy/dev/etlegacy/src/game/g_lua.c:1789
#14 0xead7a0a2 in G_InitGame (levelTime=0, randomSeed=1578, restart=0, legacyServer=1, serverVersion=274) at /home/remy/dev/etlegacy/src/game/g_main.c:2501
#15 0xead759e6 in vmMain (command=0, arg0=0, arg1=1578, arg2=0, arg3=1, arg4=274, arg5=0, arg6=0) at /home/remy/dev/etlegacy/src/game/g_main.c:667
#16 0x0806743b in VM_CallFunc (vm=0x8d282c0 <vmTable>, callnum=0) at /home/remy/dev/etlegacy/src/qcommon/vm.c:690
#17 0x0808570d in SV_InitGameVM (restart=qfalse) at /home/remy/dev/etlegacy/src/server/sv_game.c:694
#18 0x080857d0 in SV_InitGameProgs () at /home/remy/dev/etlegacy/src/server/sv_game.c:745
#19 0x0807b23f in SV_SpawnServer (server=0xffffc784 "oasis") at /home/remy/dev/etlegacy/src/server/sv_init.c:790
#20 0x0807c47d in SV_Map_f () at /home/remy/dev/etlegacy/src/server/sv_ccmds.c:151
#21 0x0807691a in Cmd_ExecuteString (text=0xffffc81c " map oasis ") at /home/remy/dev/etlegacy/src/qcommon/cmd.c:1012
#22 0x08075c17 in Cbuf_Execute () at /home/remy/dev/etlegacy/src/qcommon/cmd.c:288
#23 0x0805674d in Com_Frame () at /home/remy/dev/etlegacy/src/qcommon/common.c:3318
#24 0x08095b3e in Sys_GameLoop () at /home/remy/dev/etlegacy/src/sys/sys_main.c:950
#25 0x08095c28 in main (argc=12, argv=0xffffd174) at /home/remy/dev/etlegacy/src/sys/sys_main.c:1028

When using dynamic linking however, the script loads but I get Lua API: G_LuaStartVM error running lua script: attempt to get length of a nil value when running a test script (see attached file).

edit: With old Lua 5.2.4: Lua API: G_LuaStartVM error running lua script: multiple Lua VMs detected

#7 Updated by IR4T4 about 3 years ago

  • File test_cur_off.lua added
  • % Done changed from 10 to 80

OMG the crash is caused by the script and not by dyn lib loading itself. I’ve attached a script without retreiving a cursor (see end of script).

#8 Updated by IR4T4 about 3 years ago

  • Related to Bug #920: Fix/inspect retrieving cursor objects with LuaSQL added

#9 Updated by Spyhawk over 2 years ago

For the records:

https://dev.etlegacy.com/boards/2/topics/431?r=2697#message-2697

Still not sure how to translate that into our cmake script.

#10 Updated by Spyhawk over 2 years ago

It seems Lua 5.2+ compatibility of LuaSQL hasn’t been properly patched.

I’ve been able to make test.lua work by reverting the code to use Lua 5.1 (table.unpack should be changed back to global 'unpack’).

With Lua 5.3:

Lua 5.3 API: Loading test.lua
Lua API: G_LuaStartVM error running lua script: attempt to get length of a nil value
Lua 5.3 API: Lua VM start failed ( test.lua )

With Lua 5.2:

Lua 5.2 API: Loading test.lua
Lua API: G_LuaStartVM error running lua script: [string "test.lua"]:2: bad argument #1 to 'unpack&rsquo; (table expected, got nil)
Lua 5.2 API: Lua VM start failed ( test.lua )

With Lua 5.1:

Lua 5.1 API: Loading test.lua
Name: Jose das Couves, E-mail:
Name: Manoel Joaquim, E-mail:
Name: Maria das Dores, E-mail:
See

#11 Updated by Spyhawk over 2 years ago

Ignore all of the above. The example provided on the LuaSQL website works fine.

The issue is located in our printf function, which is buggy with Lua 5.2+.

et.G_Printf = function(...)
et.G_Print(string.format(table.unpack(arg)))
end
The length operator behavior (used internally by table.unpack) has been modified in Lua 5.2:

See also: http://stackoverflow.com/questions/23590885/why-does-luas-length-operator-return-unexpected-values

#12 Updated by IR4T4 over 2 years ago

  • Assignee set to Spyhawk
  • % Done changed from 80 to 90

#13 Updated by Spyhawk over 2 years ago

I am not sure how we can fix that erratic et.G_Printf behavior, but we can avoid it entirely by using:

et.G_Print("Name: " .. row.name .. " E-mail: " .. row.email .. "\n")

instead of

et.G_Printf = function(...)
et.G_Print(string.format(table.unpack(arg)))
end
...
et.G_Printf("Name: %s, E-mail: %s\n", row.name, row.email)

I see little reason to use et.G_Printf anyway, so let’s do that.

#14 Updated by Spyhawk over 2 years ago

  • % Done changed from 90 to 100

#15 Updated by Spyhawk over 2 years ago

  • Status changed from New to Fixed

#16 Updated by Spyhawk over 2 years ago

  • Status changed from Fixed to In Progress
  • % Done changed from 100 to 90

Should also be done for windows.

#17 Updated by Spyhawk over 2 years ago

Unfortunately get a crash with bundled sqlite3 and bundled lua:

backtrace:
#0 0x00007fffe714409f in luaH_newkey () from ./legacy/lualibs/luasql/sqlite3.so
#1 0x00007fffe7138f65 in lua_rawset () from ./legacy/lualibs/luasql/sqlite3.so
#2 0x00007fffe70a1a09 in cur_fetch (L=0x148fc48) at /home/remy/dev/etlegacy/src/luasql/ls_sqlite3.c:200
#3 0x00007fffe7a2b76e in luaD_precall () from ./legacy/qagame.mp.x86_64.so
#4 0x00007fffe7a36845 in luaV_execute () from ./legacy/qagame.mp.x86_64.so
#5 0x00007fffe7a2bb5f in luaD_call () from ./legacy/qagame.mp.x86_64.so
#6 0x00007fffe7a2bbb1 in luaD_callnoyield () from ./legacy/qagame.mp.x86_64.so
#7 0x00007fffe7a2afcf in luaD_rawrunprotected () from ./legacy/qagame.mp.x86_64.so
#8 0x00007fffe7a2be1d in luaD_pcall () from ./legacy/qagame.mp.x86_64.so
#9 0x00007fffe7a293d3 in lua_pcallk () from ./legacy/qagame.mp.x86_64.so
#10 0x00007fffe798c30a in G_LuaCall (vm=0x147c4a0, func=0x7fffe7a55b71 "G_LuaStartVM", nargs=0, nresults=0)
at /home/remy/dev/etlegacy/src/game/g_lua.c:2049
#11 0x00007fffe7990be0 in G_LuaStartVM (vm=0x147c4a0) at /home/remy/dev/etlegacy/src/game/g_lua.c:2546
#12 0x00007fffe798c226 in G_LuaInit () at /home/remy/dev/etlegacy/src/game/g_lua.c:2010
#13 0x00007fffe79968b2 in G_InitGame (levelTime=0, randomSeed=2436, restart=0, legacyServer=1, serverVersion=274)
at /home/remy/dev/etlegacy/src/game/g_main.c:2450
#14 0x00007fffe7992029 in vmMain (command=0, arg0=0, arg1=2436, arg2=0, arg3=1, arg4=274, arg5=0, arg6=0)
at /home/remy/dev/etlegacy/src/game/g_main.c:667
#15 0x000000000044296c in VM_CallFunc (vm=0x1364560 &lt;vmTable&gt;, callnum=0) at /home/remy/dev/etlegacy/src/qcommon/vm.c:690
#16 0x000000000044f94b in SV_InitGameVM (restart=qfalse) at /home/remy/dev/etlegacy/src/server/sv_game.c:694
#17 0x000000000044fa5d in SV_InitGameProgs () at /home/remy/dev/etlegacy/src/server/sv_game.c:745
#18 0x0000000000451352 in SV_SpawnServer (server=0x7fffffffd5c0 "oasis") at /home/remy/dev/etlegacy/src/server/sv_init.c:790
#19 0x0000000000445026 in SV_Map_f () at /home/remy/dev/etlegacy/src/server/sv_ccmds.c:151
#20 0x00000000004177f3 in Cmd_ExecuteString (text=0x7fffffffd660 " map oasis ") at /home/remy/dev/etlegacy/src/qcommon/cmd.c:1012
#21 0x00000000004168db in Cbuf_Execute () at /home/remy/dev/etlegacy/src/qcommon/cmd.c:288
#22 0x000000000041d10c in Com_Frame () at /home/remy/dev/etlegacy/src/qcommon/common.c:3317
#23 0x0000000000465414 in Sys_GameLoop () at /home/remy/dev/etlegacy/src/sys/sys_main.c:950
#24 0x0000000000465511 in main (argc=3, argv=0x7fffffffdff8) at /home/remy/dev/etlegacy/src/sys/sys_main.c:1056

This is the same crash as above.

#18 Updated by IR4T4 over 2 years ago

  • File deleted (test_cur_off.lua)

#19 Updated by IR4T4 over 2 years ago

  • File deleted (test.lua)

#20 Updated by IR4T4 over 2 years ago

  • % Done changed from 90 to 100

I’ve deleted the attached scripts. You can find working test script in our Lua scripts rep:
https://github.com/etlegacy/etlegacy-lua_scripts/tree/master/TESTS/luasql

#21 Updated by Spyhawk over 2 years ago

  • Status changed from In Progress to Feedback

Need feedback from people compiling under windows (especially with VS).

#22 Updated by Spyhawk over 2 years ago

  • Status changed from Feedback to In Progress
  • % Done changed from 100 to 90

#23 Updated by Spyhawk over 2 years ago

  • Status changed from In Progress to Feedback
  • % Done changed from 90 to 100

#24 Updated by Spyhawk over 2 years ago

  • Status changed from Feedback to Fixed

Also available in: Atom PDF