Is there a way to test lua code?

i was wondering if there is a way to test the code in a lua file without having to actually enable the mod and see if it works.

For example if i edit a lua file to make a new mod, the only thing i can do now, is to run the game and see if it works. Is there a program or some other way to test the lua code for any mistypes, wrong commands, etc ??

6,420 views 21 replies
Reply #1 Top

I'd love this too mate! I'm currently working on new favor items using the gkrits tab mod and i am having to do quite a lot of game starting and stopping just to check some code.

After being used to using .XML's the .lua is a much different beast to conquer.

/signed for lua tester.

Reply #2 Top

lua is a script language and not compiled. i dont know too much about scripting languages but i assume whats theoretically possible is that the syntax itself could be tested. it means that something like a missing = would be made visible by parsing the code before the gamestart. but missing functions cannot be detected before runtime. thats the stuff which usually is being handled by a linker during compiletime and that thing doesnt exist for lua.

Reply #3 Top

You can use ctrl f9 which will reload the map and the code quickly with out alot of scmap parsing. And then use the console to find any errors.

Reply #4 Top

One of the problems you'll have finding a 3rd party tool to help you do something as simple as pre-parse your file for errors is that the LUA inside Demigod is a Modified LUA language.  It has features not in the standard LUA languages.  Things like # comments, continue statements to name 2 off the top of my head.  Those right there will make any 3rd-party parse checking tool you find pretty much useless.

Edit: what he said ^^^^ :)

Reply #5 Top

To enable the console

Open the Game.prefs file (use Notepad or another text editor). For Winddows XP, this file is located in ..\My Documents\My Games\Gas Powered Games\Demigod. Add the following lines to the beginning of the file (above the 'profile = {'):

debug = { enable_debug_facilities = true }

Save the file.
Start Demigods
Change video resolution to Windowed Mode
F9 opens up the Moho logger
The logger works at the main menu and in game.
The logger consumes a ton of system resources.
Ctrl + F10 restarts the scenario

The following list are the defined debug commands in the lua. They may not all work.

    ['Ctrl-L']              = 'debug_output_logs',
    ['Ctrl-A']              = 'debug_achievements',
    ['Ctrl-Alt-P']          = 'debug_navpath',
    ['Alt-F2']              = 'debug_create_unit',
    ['Alt-T']               = 'debug_teleport',
    ['Alt-A']               = 'debug_run_opponent_AI',
    ['Ctrl-Alt-B']          = 'debug_blingbling',
    ['Alt-Delete']          = 'debug_destroy_units',

    ['Ctrl-Alt-Comma']      = 'debug_graphics_fidelity_0',
    ['Ctrl-Alt-Period']     = 'debug_graphics_fidelity_1',
    ['Ctrl-Alt-Slash']      = 'debug_graphics_fidelity_2',
    ['Ctrl-Alt-M']          = 'debug_toggle_ren_environment',

    ['Alt-F3']              = 'debug_scenario_method_f3',
    ['Shift-F3']            = 'debug_scenario_method_shift_f3',
    ['Ctrl-F3']             = 'debug_scenario_method_ctrl_f3',
    ['Shift-F4']            = 'debug_scenario_method_shift_f4',
    ['Ctrl-F4']             = 'debug_scenario_method_ctrl_f4',
    ['Ctrl-Alt-F4']         = 'debug_scenario_method_ctrl_alt_f3',
    ['Ctrl-Shift-F4']       = 'debug_scenario_method_f4',
    ['Ctrl-Shift-F5']       = 'debug_scenario_method_f5',
    ['Shift-F5']            = 'debug_scenario_method_shift_f5',
    ['Ctrl-F5']             = 'debug_scenario_method_ctrl_f5',
    ['Ctrl-Alt-F5']         = 'debug_scenario_method_ctrl_alt_f5',

    ['Shift-F6']            = 'debug_create_entity',
    ['Shift-F7']            = 'debug_show_stats',
    ['Shift-F8']            = 'debug_show_army_stats',
    ['Shift-F9']            = 'debug_show_cvp_stats',
    ['Alt-F9']              = 'debug_open_lua_debugger',
    ['Alt-F11']             = 'debug_show_frame_stats',
    ['Ctrl-Alt-W']          = 'debug_render_wireframe',
    ['Ctrl-Shift-W']        = 'debug_weapons',
    ['Ctrl-Alt-O']          = 'debug_grid',
    ['Alt-Q']               = 'debug_show_focus_ui_control',
    ['Alt-W']               = 'debug_dump_focus_ui_control',
    ['Alt-D']               = 'debug_dump_ui_controls',
    ['Alt-V']               = 'debug_skeletons',
    ['Alt-B']               = 'debug_bones',

    ['Ctrl-Shift-X']        = 'debug_redo_console_command',
    ['Ctrl-Shift-C']        = 'debug_copy_units',
    ['Ctrl-Shift-V']        = 'debug_paste_units',
    ['Alt-C']               = 'debug_cam_zoom_near',

    ['Alt-N']               = 'debug_nodamage',
    ['Ctrl-Alt-E']          = 'debug_show_emitter_window',
    ['Ctrl-Alt-R']          = 'debug_reload_effect_templates',
    ['Ctrl-Alt-Shift-R']    = 'debug_reload_effect_utilities',
    ['Ctrl-Alt-Z']          = 'debug_sally_shears',
    ['Ctrl-Shift-Alt-C']    = 'debug_collision',
    ['Ctrl-Slash']          = 'debug_pause_single_step',
    ['Ctrl-F10']            = 'debug_restart_session',

    ['Alt-F']               = 'set_level_25',
    ['Alt-G']               = 'give_all_skills',

    ['Ctrl-U']              = 'debug_ui',
    ['Ctrl-Shift-Alt-D']    = 'debug_damage',
    ['Ctrl-Shift-U']        = 'debug_dump_frames',

    ['Ctrl-Shift-E']        = 'debug_erics_ring',

    ['Ctrl-NumMinus']       = 'debug_corpse_delay_decrease',
    ['Ctrl-NumPlus']        = 'debug_corpse_delay_increase',

    ['Ctrl-K']              = 'suicide',

    ['NumMinus']            = 'decrease_game_speed',
    ['NumPlus']             = 'increase_game_speed',
    ['NumStar']             = 'reset_game_speed',
    ['Ctrl-Alt-Shift-P']    = 'pause',

Reply #6 Top

LUA inside Demigod is a Modified LUA language

meh.  LUA wasn't good enough, apparently.  Oh well... glad to have you guys on the case!

Reply #7 Top

Regular Lua actually has quite a few pitfalls when you attempt to export C++ systems, because it's a C library, so it doesn't support critical C++ features like templates and object orientation (from the API side anyway, e.g. you can't expose a member function). However, the actual syntax compared to a standard Lua 5.1.4 build is negligible, and I have a personal version with #comments and suchlike in it. I could post a "tester" exe if you like.

It's generally bad practice to use #comments anyway- you really should use --.

Reply #8 Top

 Ok i think you kinda lost me here.

Thanks a lot of trying to help:thumbsup:

I really dont understand much, but oh well.....

DeadMG, if you could post a "tester" like you said i would really appreciate it, but would i be able to use it?

As you can see, i am very noob in all this:rolleyes:

Reply #9 Top

morpheas, use scite or notepad++ and f9 and strg+f10 for maprestart. it should be good enough.

Reply #11 Top

You can freely edit existing mods while demigod is running and use the console and Ctrl+f10 to reload them (as Derog states). However, if you wish to add a new mod, you'll have to restart demigods.

Reply #12 Top

Ok thank you guys:thumbsup:

Too much help he he:grin:   I am all set.

Reply #13 Top

Quoting Ptarth, reply 11
You can freely edit existing mods while demigod is running and use the console and Ctrl+f10 to reload them (as Derog states). However, if you wish to add a new mod, you'll have to restart demigods.

that sometimes aint enough. i'm trying to build some really rudimentary form of a tower defense mod for others to go on with (because i dont have the time) and have to edit the conquest.lua. the problem is: if it cant be parsed, the game hangs on loading and has to be shutdown by killing the process.

Reply #15 Top

Tester gonna be posted soon then.

 

Derog:

In Conquest.lua, just use
local ok, msg = pcall(doscript, "Filepath")
if not ok then
    LOG(msg)
    doscript("old conquest.lua filepath")
end 

 

http://www.filefront.com/15009705/lua_pftest.exe

This will attempt to launch test.lua in the same directory. Any errors will be output to the console window. Both #comment and continue loop statement are fully supported.

Just a note - Lua 5.1.4 requires for k, v in pairs(table), not for k, v in table. I've tried to remove this without success in the past. However, SupCom's Lua should fully support for k, v in pairs(table), so it's only good practice to use this instead of table directly.

Reply #16 Top

I thinking about when a 'tower defence' map would end... and I thought of a cool concept... but it would require new MAPs:

It would be a 'vs.' tower defence... same concept as now, but the flags on your side would effect the other side; and the citidel upgrades would make the creeps your enemy fights stronger!... basically you try and screw with the other team till their citadel gets destroyed.

It would require maps that are 2 'seperate' terrains that don't mix (so you can't unfairly go over to the other side).

It sounds like it would be fun but it would be a lot of work to get it up and running.

Reply #17 Top

hey, deadmg thanks for the tip. i didnt look for exception handling yet because i was busy trying to recompile notepad++ or scite with an edited lua lexer. compiling worked but then it threw an error right at the start which i didnt investigage further. then i got back to textadept which supports dynamic lexing by lpeg (a lua lexing library) and now im using that. this editor is also very easy to mod because many parts are written in lua but the downside is that its really just a very simple editor.

your tool doesnt work for me. it shows an error that i dont have the msvcr100.dll.

Reply #18 Top

your tool doesnt work for me. it shows an error that i dont have the msvcr100.dll.

It doesnt work for me either.

It gives me this message:

http://img690.imageshack.us/img690/7/luatesterror.jpg

Why is that?

Reply #19 Top

Goto http://pcsx2.dyndns.org/, click the little disk icon at the top of the page to download/install vc++ 2010 beta redistributable.  I think that will fix the error.

Reply #21 Top

the tester doesnt know import. says its a nil value. could it be that it doesnt work for this special lua version, since import is not a standard lua function.