Wesnoth Lua Pack: Development Thread

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

Moderator: Forum Moderators

Post Reply
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Wesnoth Lua Pack: Development Thread

Post by melinath »

Hey, guys! Glad to see someone picked this up! :-)

Recently, I've been frustrated with the command line as a tool for testing lua code in-game. I'm working on a lua debug shell and I was wondering whether you might be able to give me some feedback. I've attached the code, or you can view it at https://gist.github.com/956351 The idea would be to eventually submit this for inclusion in the WLP.

Problems I'm having (mostly GUIWML related):
1. Location of the shell dialog. I'd like the shell to show up at the bottom of the screen. It currently shows up in the middle of the screen, and since you can't scroll while a dialog is up, whatever you're probably looking at gets blocked. Any chance you know how to relocate a dialog?

2. Alignment of the text. Theoretically, things automatically align left. I've even explicitly set the alignment to be left - but everything's still centered.

3. Redirection of stdout. Ideally, inputting: print "hello world" would output to the output area... but it currently prints to the terminal. From a cursory check, I think that stdout redirection would require the i/o library, which is not available. However, I think it might be possible to set up an environment for the shell commands where "print" is replaced by another function - perhaps "return" or "shell_print" or something like that. Does that seem reasonable, or am I way off base?

4. Autofocus of the text area. Would be nice, but it doesn't look like it's possible. Hopefully I'm wrong.

Edit:: Added screenshots.
Attachments
outputs return values (currently naive)
outputs return values (currently naive)
Runs with the current global context.
Runs with the current global context.
Error reporting.
Error reporting.
shell.lua
(1.07 KiB) Downloaded 1091 times
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter »

melinath wrote:The idea would be to eventually submit this for inclusion in the WLP.
You can submit it by yourself: you just need to create an account on Sourceforge, and then contact an admin of the Wesnoth-UMC-Dev project to have commit access (in my case was Espreon). :)
melinath wrote:Problems I'm having (mostly GUIWML related):
I wasn't able to make any Wesnoth GUI stuff until now, so you're in a better situation than me. Mainly I didn't understood how to use T.grid, T.row and T.column - can you kindly explain me how? I'm sure that I'll have other questions about it... :mrgreen:
melinath wrote:3. Redirection of stdout. Ideally, inputting: print "hello world" would output to the output area... but it currently prints to the terminal. From a cursory check, I think that stdout redirection would require the i/o library, which is not available. However, I think it might be possible to set up an environment for the shell commands where "print" is replaced by another function - perhaps "return" or "shell_print" or something like that. Does that seem reasonable, or am I way off base?
For what I know, print is like a shortcut to the standard output. You can define your own print function - although this may clash with other code that will use print for debug purposes if you use it as global, and may not have the desired effect if used as local. Not having the I/O library, using return seems a concrete option.
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)
Exasperation
Posts: 462
Joined: June 8th, 2006, 3:25 am

Re: Wesnoth Lua Pack: Development Thread

Post by Exasperation »

1. Try looking at http://wiki.wesnoth.org/GUIToolkitWML#Resolution_2, that's where I eventually found the reference for the [tooltip] and [helptip] part. In particular, I think you could also include a vertical_placement child at the same level as [tooltip], [helptip], and [grid] to get the result you want (follow the v_align link to see possible values). I think the entry you want is just

Code: Select all

vertical_placement = "bottom"
-Note: I haven't tried this myself yet.-

2. Check out http://wiki.wesnoth.org/GUIToolkitWML#Cell and also follow the link from there to GUILayout. Try something like

Code: Select all

T.column {
	horizontal_alignment = "left",
	T.label {
		id = "shell_output",
		text_alignment = "left"
	}
}
Edit - @Elvish Hunter the GUILayout page is probably the explanation of how to use grid, row, and column that you're looking for, or at least a starting point.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus »

@melinath

My addons contain a right-click-menu usable only in debug mode. It recompiles and executes a "main" function. The body of that function in my lua editor is sort of my "shell input", it lets me test all kinds of wesnoth-allowed lua and action wml on-the-fly without scenario reloads or even "back to turn x". Output is the chat area just as yours....
Also the way I test new or changed action wml in the core engine.
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
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Wesnoth Lua Pack: Development Thread

Post by melinath »

@Exasperation: Thanks for the tips! I hadn't caught that bit in GUIToolkit... man, the docs on this are terrible. :-p In any case, the vertical and horizontal alignment issues are now fixed. Current version is attached, and at https://gist.github.com/956351.

@Anon: I can't find the code that you mention, but I did find a main.lua file in The Earth's Gut. If I understand correctly, you're referring to a menu item which would run a command like:

Code: Select all

[lua]
    code = <<
        main = wesnoth.dofile("~add-ons/MyAddOn/lua/main.lua")
        main.main()
    >>
[/lua]
That does sound useful, but it's a bit different than what I'm trying to set up. For example, my goal is to display stdout to the "shell" area rather than the chat area.

@all: I'm still hoping to find a solution for autofocus and output redirection. Oh, and I forgot to mention that I am having issues with text box history... as in it isn't working. Any insight would be greatly appreciated!
Attachments
shell.lua
(1.06 KiB) Downloaded 844 times
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus »

melinath wrote:If I understand correctly, you're referring to a menu item which would run a command like:

Code: Select all

[lua]
    code = <<
        main = wesnoth.dofile("~add-ons/MyAddOn/lua/main.lua")
        main.main()
    >>
[/lua]
Exactly. From what I understand, your shell executes a one-line code when pressing "enter" ? With that you can execute whatever arbitrary code, and no copy-paste needed. The same code can afterwards just be called by a regular wml event (as opposed to a menu item) without changing the file.
For example, my goal is to display stdout to the "shell" area rather than the chat area.
Why don't you create a shortcut function e.g. "dbms" which is less to write than "print" and passes its argument to wesnoth.message ?

Anyway, silene left us. We're on our own regarding lua. You can join the club at the umc repository however.
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
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Wesnoth Lua Pack: Development Thread

Post by melinath »

New version at https://gist.github.com/956351. I'm happy to report that this version redirects "print" to the shell output area, as well as storing all output rather than just the most recent item. However, it gets awfully slow if you run more than ~7 cycles. I'm guessing it's due to the recursion.

Edit: Removing the recursive call made it much snappier. :-)

@Anon: TBH, I don't really like wesnoth.message as a vehicle for debugging information. I find it hard to read...
I certainly do appreciate the value of your method for testing arbitrary code; my shell will probably never be able to handle things like that, even with copy-paste.
However, I'm looking more for a method of dealing with spontaneous single-line snippets like "print(x)" where the time required to switch to a text editor, write it out, switch back, and use a menu item to reload the file would just not be worth it. And while :lua is not that hard to type, it gets to be a drag having to type it for every single command that I want to use.
Exasperation
Posts: 462
Joined: June 8th, 2006, 3:25 am

Re: Wesnoth Lua Pack: Development Thread

Post by Exasperation »

I did some more poking around in the documentation, and I found some things that may apply to the problem of auto-focusing on the textbox. First, from http://wiki.wesnoth.org/GUIWidgetDefinitionWML#Text_box:
The following states exist:
state_enabled, the text box is enabled.
state_disabled, the text box is disabled.
state_focussed, the text box has the focus of the keyboard.
So it looks like you want to set the state of the textbox to state_focussed. Second, from http://wiki.wesnoth.org/LuaWML:Display# ... log_canvas:
The meaning of the canvas index depends on the chosen widget. It may be the disabled / enabled states of the widget, or its background / foreground planes, or...
So it may be possible to use wesnoth.set_dialog_canvas to do so. On the other hand, I have no idea what canvas index you would need, or even if I'm interpreting these passages correctly. It will probably take some experimentation and/or examining the source code to figure it out.
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Wesnoth Lua Pack: Development Thread

Post by melinath »

Hmm. My interpretation of the docs was a little different: that set_dialog_canvas lets you change how the dialog is displayed for a given state. AFAICT widget definitions are essentially statically defined in the core wml and can't be overridden by instances in most matters, and it seems like the state can only be changed by the game engine. It would be nice to be wrong, though.
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter »

Exasperation wrote:Edit - @Elvish Hunter the GUILayout page is probably the explanation of how to use grid, row, and column that you're looking for, or at least a starting point.
Thanks! :D When I'll have some spare time I'll try to do something about it. I didn't had time to do any testing, however let's see if I understood correctly:
- each row must have a [row] tag;
- each row must have the same amount of [column] tags, one for each column;
- unlike Tkinter, there is no rowspan or columnspan, so if a widget requires two columns I need to remove one column from all the rows and place another [grid] where I need to split a cell in two.
So, the resulting structure for a 2 rows x 3 columns dialog is:

Code: Select all

 { T.grid
    { T.row { T.column {}, T.column {}, T.column {} },
    T.row { T.column {}, T.column {}, T.column {} } } }
I didn't tested it yet; am I right, or there is some error (except for the missing widget, that I haven't tried)?
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)
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Wesnoth Lua Pack: Development Thread

Post by melinath »

Yes, that's a correct grid. But if you want to use the table for a dialog, you'll also need to have vestigial [tooltip] and [helptip] sections. See:
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter »

Version 1.3.0 of Wesnoth Lua Pack is now on the 1.9 add-ons server. It includes several new tags, like the math tags by Espreon and two GUI tags made by me. Due to the changes needed in core to make GUI WML and Lua working correctly (thanks again to Exasperation, by the way :wink: ), this version of WLP will work as intended only from Wesnoth 1.9.7+svn and 1.9.8 onwards.
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)
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus »

Elvish_Hunter wrote:Due to the changes needed in core to make GUI WML and Lua working correctly (thanks again to Exasperation, by the way :wink: ), this version of WLP will work as intended only from Wesnoth 1.9.7+svn and 1.9.8 onwards.
An attempt to load the wlp with a not recent enough BfW version will cause a meaningful error message. ^_^
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
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus »

Your debug dialogs are severely broken when used in networked multiplayer since they aren't synced. I haven't been able to sync it so far, the problem is that it seems I can only either sync the values set by the postshow function or the value returned by show_dialog (clicked cancel etc). You can test yourself e.g. with the Plan_Your_Advancements_Era UMC dev version.

EDIT
Finally managed it. The unit debug dialog still needs synchronization, you like to figure that out yourself I guess.
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
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter »

Thank you, I'll fix it as soon as I can.
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)
Post Reply