Wesnoth Lua Pack: Development Thread
Moderator: Forum Moderators
Re: Wesnoth Lua Pack: Development Thread
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.
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
-
- shell.lua
- (1.07 KiB) Downloaded 1108 times
- Elvish_Hunter
- Posts: 1584
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Wesnoth Lua Pack: Development Thread
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:The idea would be to eventually submit this for inclusion in the WLP.
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...melinath wrote:Problems I'm having (mostly GUIWML related):
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.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?
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)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: Wesnoth Lua Pack: Development Thread
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
-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
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.
Code: Select all
vertical_placement = "bottom"
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"
}
}
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Wesnoth Lua Pack: Development Thread
@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.
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 starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: Wesnoth Lua Pack: Development Thread
@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:
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!
@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]
@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 863 times
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Wesnoth Lua Pack: Development Thread
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.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]
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 ?For example, my goal is to display stdout to the "shell" area rather than the chat area.
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 starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: Wesnoth Lua Pack: Development Thread
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.
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.
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: Wesnoth Lua Pack: Development Thread
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:
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 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 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.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...
Re: Wesnoth Lua Pack: Development Thread
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.
- Elvish_Hunter
- Posts: 1584
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Wesnoth Lua Pack: Development Thread
Thanks! 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: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.
- 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 {} } } }
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)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: Wesnoth Lua Pack: Development Thread
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:
- Elvish_Hunter
- Posts: 1584
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Wesnoth Lua Pack: Development Thread
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 ), 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)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Wesnoth Lua Pack: Development Thread
An attempt to load the wlp with a not recent enough BfW version will cause a meaningful error message.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 ), this version of WLP will work as intended only from Wesnoth 1.9.7+svn and 1.9.8 onwards.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Wesnoth Lua Pack: Development Thread
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.
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 starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
- Elvish_Hunter
- Posts: 1584
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Wesnoth Lua Pack: Development Thread
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)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)