Problems on Debuging/Logging

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
IArgosyI
Posts: 6
Joined: October 22nd, 2012, 7:28 am

Problems on Debuging/Logging

Post by IArgosyI »

Hi, I'm really new to Lua, and now I face some problems.

I don't know how to log the information. - -

I've tried print(), but I still don't know how to view the "console" that it print to.

I've also tried the following command, but it showed me that it is error.

Code: Select all

local file = io.open("example.txt", "w")
file:write("....................")
file:close()
So if you guys can tell me how to properly print out or save to file, it would be a big help.

Thx

P.S. for now I've used wesnoth.message() but the output in the game is limited to 5-6 lines, so it didn't help me much
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Problems on Debuging/Logging

Post by Elvish_Hunter »

IArgosyI wrote:So if you guys can tell me how to properly print out or save to file, it would be a big help.
You can't. The io library and part of the os library are disallowed for security reasons. If they weren't, it will be possible for everyone with enough knowledge to load on the server a malicious add-on that executes arbitrary code.
At most, you can use the print() function to print stuff on the Terminal (on Linux) or on the stdout.txt (on Windows). Look here to find it (you'll find it in the same directory where stderr.txt can be found, but only when Wesnoth is running):
http://wiki.wesnoth.org/EditingWesnoth# ... rectory.3F
http://forums.wesnoth.org/viewtopic.php?f=4&t=23894
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
IArgosyI
Posts: 6
Joined: October 22nd, 2012, 7:28 am

Re: Problems on Debuging/Logging

Post by IArgosyI »

Wow thank you very much :)
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Problems on Debuging/Logging

Post by Anonymissimus »

Elvish_Hunter wrote:
IArgosyI wrote:So if you guys can tell me how to properly print out or save to file, it would be a big help.
You can't.
However, when launching wesnoth (any program ?) from the console, you can redirect the stderr and stdout into a file or files.
In an ubuntu bash shell for instance (untested):
wesnoth -d --log-debug=all 1>stdout.txt 2>stderr.txt
Such files could (should) be added to a bug which you report.
On windows, I think one is forced to use the files with these names.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Post Reply