ORIGINAL: Blond_Knight
Im not saying we need an editor for the lua files but how about a syntax checker? ...
You mean like the standard Lua compiler luac?
rober@Rob10rto /cygdrive/c/Documents and Settings/rober/My Documents/Games/Matrix Games/Images
$ luac -p "$VN/mods/DEV - Test Scenarios"/*.lua "$VN/mods/DEV - Test Scenarios/scenarios"/*.lua
luac: ... - Test Scenarios/scenarios/LA_671216_phou-den-din_H.lua:224: 'then' expected near 'move_rush'
[:)]
A support utility I wrote to work together with luac, take a gander at this:
ORIGINAL: berto
Let's see if I can make your heads hurt.
The source code to txt.l, the heart of the new lstrip.exe utility (one component of csluachk.pl):
Needless to say (?), get even just a single ; out of place, omit a vital \ or whatever, the whole thing falls apart, won't compile (translate into machine code). It all has to be
just so.
In addition, I have at least one other home-grown utility, csluachk.pl, to check the Lua scripts in various other ways, for example:
rober@Rob10rto ~/cslint
$ ./csluachk.pl -G -n -w +e -g vn
...
ERROR: for VN_510327_Mao_Khe_H.lua:226: mistaken side: FRENCHSIDE
ERROR: for VN_510327_Mao_Khe_H.lua:226: mistaken side parameter: inc_event_points(FRENCHSIDE, ...)
ERROR: for VN_510327_Mao_Khe_H.lua:254: mistaken side: FRENCHSIDE
ERROR: for VN_510327_Mao_Khe_H.lua:254: mistaken side parameter: inc_event_points(FRENCHSIDE, ...)
ERROR: for VN_510327_Mao_Khe_H.lua:282: mistaken side: FRENCHSIDE
ERROR: for VN_510327_Mao_Khe_H.lua:282: mistaken side parameter: inc_event_points(FRENCHSIDE, ...)
ERROR: for VN_510327_Mao_Khe_H.lua:354: mistaken nation parameter: inc_morale_shift(FRENCH_SIDE, ...)
ERROR: for VN_510327_Mao_Khe_H.lua:370: mistaken nation parameter: inc_morale_shift(FRENCH_SIDE, ...)
ERROR: for VN_510327_Mao_Khe_H.lua:387: mistaken nation parameter: inc_morale_shift(VIET_MINH_SIDE, ...)
ERROR: for VN_510327_Mao_Khe_H.lua:403: mistaken nation parameter: inc_morale_shift(VIET_MINH_SIDE, ...)
...
ERROR: for VN_521201_Na_San_H.lua:443: mistaken side: French_SIDE
ERROR: for VN_521201_Na_San_H.lua:473: mistaken side: French_SIDE
ERROR: /usr/local/bin/luac: ...rix Games/Vietnam/vietnam/scenarios/VN_540404_PK15_H.lua:208: 'then' expected near 'if'
...
ERROR: for VN_480810_Gionc_Dinh_A.lua:104: mistaken objective hex coordinates: objective_owner(15,11)
ERROR: for VN_480810_Gionc_Dinh_A.lua:110: mistaken objective hex coordinates: objective_owner(15,11)
ERROR: for VN_480810_Gionc_Dinh_A.lua:116: mistaken objective hex coordinates: objective_owner(15,11)
WARNING: in VN_480810_Gionc_Dinh_A.lua, referenced just once: VP_2_CAPTURED
WARNING: in VN_480810_Gionc_Dinh_A.lua, referenced just once: VP_3_CAPTURED
...
WARNING: for LA_630915_SamNeua_A.lua, missing or mistaken on_resume()
WARNING: for LA_630915_SamNeua_A.lua, missing or mistaken on_shutdown()
WARNING: for LA_630915_SamNeua_A.lua, missing or mistaken on_next_phase()
WARNING: for LA_630915_SamNeua_A.lua, missing or mistaken on_next_turn()
...
And many other possible errors.
Im assuming if you call a variable that doesn't exist it'll output to the log file?
Yes, the Lua interpreter will surely log all significant errors (in the standard game log files engine.log & error.log, but also optionally in the new lua.log), for example:
rober@Rob10rto /cygdrive/r/Temp/logs
$ cat error.log
2018-07-31 05:16:36 vnengine.exe: [ERROR ID 3000] (lua.cpp, line 317, Lua::Load()) user.lua file load error: user.lua:178: 'end' expected ( to close 'function' at line 88) near <eof>
2018-07-31 05:16:59 vnengine.exe: [ERROR ID 3000] (appl.cpp, line 3186, ApplWindow::LOnNextPhase()) in ApplWindow::LOnNextPhase, error running function 'on_next_phase': scenarios\MoveWayPointTest1.lua:67: attempt to call a nil value (global 'move_way_point')
By means of the CSEE log() command
FUNCTION
log (logfile, loglevel, msg)
DESCRIPTION
Log a message, at the given level, to one of the standard game log files.
INPUTS
logfile -- any of
ERRLOG
APPLOG
LUALOG
loglevel -- any of
LOG_DEBUG
LOG_INFO
LOG_NOTICE
LOG_WARNING
LOG_ERROR
text -- character string, or some function or expression evaluating to a character string
RETURN VALUE
none
EXAMPLES
log(LUALOG, LOG_INFO, "entering on_startup(), turn is " .. current_turn())
log(APPLOG, LOG_INFO, "entering on_startup(), turn is " .. current_turn())
log(ERRLOG, LOG_ERROR, "unit trackid " .. trackid .. " does not exist")
SEE ALSO
message ()
message_once ()
_message ()
note ()
note_once ()
_note ()
debug ()
and its cousins (the SEE ALSO), you can log the CSEE up the wazoo.
A sample use:
log(LUALOG, LOG_DEBUG,
"turn " .. current_turn() ..
", i " .. i ..
", j " .. j ..
", trackid " .. trackid ..
", loc " .. loc ..
", from " .. from ..
", to " .. to
)
And its corresponding lua.log file output:
rober@Rob10rto /cygdrive/r/Temp/logs
$ cat lua.log
2018-07-31 07:52:44 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) turn 2, i 1, j 3, trackid 293, loc 59,78, from 59,73, to 50,68
2018-07-31 07:52:44 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) turn 2, i 1, j 2, trackid 293, loc 59,78, from 50,73, to 59,73
2018-07-31 07:52:44 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) turn 2, i 1, j 1, trackid 293, loc 59,78, from 59,78, to 50,73
2018-07-31 07:52:44 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) moveit(), trackid 293, hexcoor 50,73
2018-07-31 07:52:48 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) turn 3, i 1, j 3, trackid 293, loc 56,76, from 59,73, to 50,68
2018-07-31 07:52:48 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) turn 3, i 1, j 2, trackid 293, loc 56,76, from 50,73, to 59,73
2018-07-31 07:52:48 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) turn 3, i 1, j 1, trackid 293, loc 56,76, from 56,76, to 50,73
2018-07-31 07:52:48 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) moveit(), trackid 293, hexcoor 50,73
2018-07-31 07:52:53 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) turn 4, i 1, j 3, trackid 293, loc 53,75, from 59,73, to 50,68
2018-07-31 07:52:53 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) turn 4, i 1, j 2, trackid 293, loc 53,75, from 50,73, to 59,73
2018-07-31 07:52:53 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) turn 4, i 1, j 1, trackid 293, loc 53,75, from 53,75, to 50,73
2018-07-31 07:52:53 vnengine.exe: [DEBUG ID 10] (lua.cpp, line 445, l_log()) moveit(), trackid 293, hexcoor 50,73
...
Oh, yes, there will be all sorts of diagnostic support for the CSEE Lua scripting, much of it home-grown. Lots of possibilities here, but lots of pitfalls also. We'll try to help you avoid the pits.