test: Use a better error message when code.lua doesn't exist (#1722)

This commit is contained in:
Luther 2017-06-06 07:55:49 -04:00 committed by Celtic Minstrel
parent fda7bf63af
commit 5ba35e42b1
2 changed files with 17 additions and 1 deletions

View file

@ -1286,6 +1286,10 @@
[entry]
name = "Luiz Fernando de Faria Pereira (lfernando)"
[/entry]
[entry]
name = "Luther Thompson"
email = "lutheroto_AT_gmail.com"
[/entry]
[entry]
name = "lv-zheng"
[/entry]

View file

@ -1397,7 +1397,19 @@ My best advancement costs $next_cost gold and Im $experience|% there."
# The file is not in the repository to allow adding custom stuff to it.
[command]
[lua]
code=<< wesnoth.dofile("lua/code.lua").main() >>
code=<<
local codeFile = "lua/code.lua"
if wesnoth.have_file(codeFile) then
local code = wesnoth.dofile(codeFile)
if type(code) == "table" and type(code.main) == "function" then
code.main()
else
wesnoth.message(codeFile.." must return a table with a 'main' function.")
end
else
wesnoth.message("To use this command, create a file 'data/lua/code.lua' in the wesnoth source directory that returns a table with a 'main' function.")
end
>>
[/lua]
[/command]
[/set_menu_item]