Wesnoth Lua Pack: Development Thread

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

Moderator: Forum Moderators

Post Reply
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus »

Also, I wonder how other people using the WLP load it. As far as I'm concerned I'm loading it "as minimally as possible", that is, not always all the tags, since I'm generally afraid of conflicts or overwrites, if my addon happens to have a tag with that same name my tag could get overwritten with an implementation I don't want. That is, I suggest that all tags in the WLP should have unique names, e.g. [wlp_show_quick_debug] or such. Unfortunately this breaks backwards compatibility now so we'd have to use helper.deprecate a lot.
Then the loading structure could be changed so that a loader.cfg (similar...) loads all tags and the wml too, since I added these macros for using the debug dialogs.

EDIT
Another idea to prevent accidental overwrites: Using

Code: Select all

if not wml_actions.some_tag then
    function wml_actions.some_tag()
    ...
    end
end
blocks
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 »

I fixed the unit debug dialog: it needs some testing to confirm that works fine in multiplayer, but I don't have the time to do it right now.
I use WLP by copypasting only the tags that I need, as this eliminates a dependency requirement.
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
Espreon
Inactive Developer
Posts: 630
Joined: June 9th, 2007, 4:08 am

Re: Wesnoth Lua Pack: Development Thread

Post by Espreon »

I too just take what I need.
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Wesnoth Lua Pack: Development Thread

Post by melinath »

The problem with [wlp_show_quick_debug] is that it's very long, which is conducive to not overriding other implementations, but is not conducive to ease of WML coding.

IMHO if people are just copy-pasting the necessary tags, it eliminates the point of having the WLP. If they're concerned about loading tags that they don't need, then there should be a more differentiated way of loading tags. In ModularLua, for example, each tag is in a separate file which can be loaded or not by the person making the 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 »

melinath wrote:IMHO if people are just copy-pasting the necessary tags, it eliminates the point of having the WLP.
Not exactly. So far, all the people that posted (Anonymissimus, me, Espreon, you) have Lua knowledge. But there are many people out there that know only WML. For us, WLP is more or less like a repository; for them, is an all-in-one package that doesn't override core tags, and that grants them some advanced functions without learning another language. :wink:
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
Espreon
Inactive Developer
Posts: 630
Joined: June 9th, 2007, 4:08 am

Re: Wesnoth Lua Pack: Development Thread

Post by Espreon »

I agree with Elvish_Hunter.

Also, the main reason I don't have my addons load the WLP is that I don't want a dependency. But, that's just me.
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Wesnoth Lua Pack: Development Thread

Post by melinath »

@Elvish_Hunter: I agree with everything you said, which is why I don't think it makes sense for people to copy-paste. If it's a repository, you should use the version in the repository. If it's a group of tags, you should be able to use them without needing to copy-paste. That's easier for people who don't code.

@Espreon: If people don't want to use dependencies, why does the feature even exist?
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.4.0 of the WLP is on the 1.9 add-ons server and on UMC-Dev. This time, there are three new tags, [find_path] was removed after being mainlined, and the RTF readme is replaced by a HTML readme; for those concerned about security, it is pure HTML/CSS, without Javascript (that I still have to learn :oops: ) or every other script.
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 »

Something I put together for other reasons, that might go well in the WLP:

Code: Select all

function wesnoth.wml_actions.custom_dialog(cfg)
	local layout = helper.get_child(cfg, "layout") or helper.wml_error("[custom_dialog] missing required [layout] tag")
	local preshow, postshow
	if cfg.preshow then
		preshow = loadstring(cfg.preshow)
	end
	if cfg.postshow then
		postshow = loadstring(cfg.postshow)
	end
	wesnoth.show_dialog(layout, preshow, postshow)
end
it could probably use slightly more thorough error handling, but it works. The preshow and postshow attributes work like the code attribute in the [lua] tag, so usage looks something like this (note that preshow/postshow are not required attributes):

Code: Select all

[custom_dialog]
	[layout]
		[tooltip]
			id = "tooltip_large"
		[/tooltip]
		[helptip]
			id = "tooltip_large"
		[/helptip]

		[grid]
			[row]
				[column]
					[button]
						id = "some_widget"
						label = _"Do Stuff"
					[button]
				[/column]
			[/row]
			[row]
				[column]
					[button]
						id = "ok"
						label = _"OK"
					[button]
				[/column]
			[/row]
		[/grid]
	[/layout]
	preshow = <<
		wesnoth.set_dialog_callback(some_lua_function, "some_widget")
	>>
[/custom_dialog]
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, the main problem with a solution like this is that all the Lua tags in the WLP follow a simple rule: they must be usable even from UMC authors that don't know Lua. Both preshow and postshow are Lua functions...
Also, the grid structure is quite complex, because it does not allow use of rowspan and columnspan. To work around this and simplify the structure, in my Lua code I tend to assign every grid to a variable, a thing that here cannot be done.
Finally, the resulting dialog is not synchronized, so it's unusable in multiplayer.
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
Bonteaux
Posts: 22
Joined: November 10th, 2011, 6:49 pm

Re: Wesnoth Lua Pack: Development Thread

Post by Bonteaux »

Here's a tag that might be useful for the WLP:

Code: Select all

[store_faction_name]
It takes as arguments a unit type and a variable name and stores the corresponding faction name in the variable.

Rough Example:

Code: Select all

# in the side definition:
[side]
    # blah blah blah
    id=side1_leader
[/side]

# then, inside an event or somewhere
[store_unit]
    [filter]
        id=side1_leader
    [/filter]
    variable=side1_leader
[/store_unit]

[store_faction_name]
    leader=$side1_leader.type
    variable=side1_faction
[/store_faction_name]

[message]
    speaker=narrator
    message="Oh no! We're facing $side1_leader.name of the $side1_faction! We're doomed!!"
[/message]
The lua part goes like this:

Code: Select all

-- just copied over from the various default faction cfg files
local leader_type_factions_list = {
   ["Loyalists"] = {"Lieutenant", "Swordsman", "Pikeman", "Javelineer", "Shock Trooper", "Longbowman", "White Mage", "Red Mage"},
   ["Rebels"] = {"Elvish Captain", "Elvish Hero", "Elvish Ranger", "Elvish Marksman", "Elvish Druid", "Elvish Sorceress", "White Mage", "Red Mage", "Elder Wose"},
   ["Northerners"] = {"Orcish Warrior", "Troll", "Troll Rocklobber", "Orcish Crossbowman", "Orcish Slayer"},
   ["Undead"] = {"Dark Sorcerer", "Revenant", "Deathblade", "Bone Shooter", "Necrophage"},
   ["Knalgan Alliance"] = {"Dwarvish Steelclad", "Dwarvish Thunderguard", "Dwarvish Stalwart", "Rogue", "Trapper"},
   ["Drake"] = {"Drake Flare", "Fire Drake",  "Drake Arbiter", "Drake Thrasher", "Drake Warrior", "Saurian Oracle", "Saurian Soothsayer"}
}
-- this table will hold the actual faction mapping
local leader_type_factions = {}

-- fills the actual mapping table
local function create_leader_type_factions ()
   for faction,types in pairs(leader_type_factions_list) do
      for i=1,#types do
            leader_type_factions[types[i]]=faction
      end
   end
end

-- returns the faction name
local function store_faction_name (t)
   wesnoth.set_variable(t.variable, leader_type_factions[t.leader])
end

-- build the mapping table
create_leader_type_factions()
-- register new tag
wesnoth.register_wml_action("store_faction_name", store_faction_name)
Well, maybe it'll be useful...
"UM BROK HIT YOU!" -- Um Brok, Swamplings
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.5.0 of the WLP is on the 1.10 add-ons server and on UMC-Dev. Once again, there are some new WML tags, and the complete changelog in HTML format is included within the add-on. :)
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
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Wesnoth Lua Pack: Development Thread

Post by Celtic_Minstrel »

I notice [narrate] doesn't support all the extra features of [message]: [show_if], side_for, caption, duration, sound, [option], and [text_input], to list all the ones not related to the speaker. I think I could understand not supporting [option] or [text_input] (since once you have those it's not really narration anymore), but [show_if] and side_for at least seem like they'd be useful for narration.

It seems that [scatter_units] behaves differently from {SCATTER_UNITS} with respect to how the list of types is handled. The macro loops through the list, placing one of each type in order and returning to the start once the last type is placed (if there are more units to place), if I understand its code correctly. The tag chooses a random type from the list. Personally I think the latter behaviour is more useful, but it may be something that should be mentioned in the documentation in case someone was relying on the ordered behaviour of the macro and then decided to switch to the tag. (That said, I may use WLP just for this one tag.)

It's not at all clear that the reversal referred to in the [reverse_value] tag documentation is in fact string reversal.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
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 »

Celtic_Minstrel wrote:I notice [narrate] doesn't support all the extra features of [message] ... [show_if] and side_for at least seem like they'd be useful for narration.
Interesting suggestion. I'll do it. :)
Celtic_Minstrel wrote:It seems that [scatter_units] behaves differently from {SCATTER_UNITS} with respect to how the list of types is handled. ... Personally I think the latter behaviour is more useful, but it may be something that should be mentioned in the documentation in case someone was relying on the ordered behaviour of the macro and then decided to switch to the tag. (That said, I may use WLP just for this one tag.)
Yes, you understood the macro correctly. I'll correct the documentation. And I'm glad that you like this different behaviour.
Celtic_Minstrel wrote:It's not at all clear that the reversal referred to in the [reverse_value] tag documentation is in fact string reversal.
There's more: in that tag, I use a Lua functon called string.reverse(). It's not even mentioned in the official Lua documentation, and I found it completely by chance (for example, here). Then I thought that it would have been a nice novelty tag 8) . Again, I'll correct the documentation.

EDIT: In revision 15709, I committed to UMC-Dev an improved version of [narrate], that supports all the stuff already supported by [message], while in revision 15710 I updated the documentation for [scatter_units] and [reverse_value].
Last edited by Elvish_Hunter on August 24th, 2012, 9:46 am, edited 1 time in total.
Reason: Notified two commits
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
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.6.0 of the WLP is on the 1.11 add-ons server and on UMC-Dev. This release features a new WML tag and improvements to some existing tags. Changelog and HTML "wiki" are included with the add-on.
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