Wesnoth Lua Pack: Development Thread

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

Moderator: Forum Moderators

Post Reply
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: Wesnoth Lua Pack: Development Thread

Post by monochromatic »

wlp_tags.lua -> wml_tags.lua
For example.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus »

Thanks, fixed. This seemed to be the only problem 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
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus »

@E_H
Using rtf as the documentation file format will possibly not cope well with svn btw if you want to put it into the repository anywhen.
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 know. Probably now the WLP needs its own wiki page, so we can drop the RTF, do you agree? If yes, here there is its link (still empty): http://wiki.wesnoth.org/Wesnoth_Lua_Pack
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
Alarantalara
Art Contributor
Posts: 786
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Wesnoth Lua Pack: Development Thread

Post by Alarantalara »

RTF from a word processor is no worse than generated HTML and works pretty well if you don't use Word to generate it. Take a look at the file I sent you in a text editor that won't style the RTF if you want an example.
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 already did, also the page about RTF at Wikipedia explains well the question. The real problems is, do we prefer having an RTF inside the add-on, a wiki page, or both? Perhaps the wiki page will be better (especially if more people contribute Lua stuff in future), as it will allow collaborative editing.
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 »

As for a wiki page or even a documentation file alone - I think it's overambitious.
Consider the fact that the wesnoth C++ source is hardly documented at all, there are only few comments (sometimes) in there although there are a lot more developers than here. Consider that there are lots of wiki pages such as the one for ASC which are outdated since people don't have time to care for them.
What we should do is some comments right above the functions, everything else is too much maintenance load.
Collaborative editing is possible as well if rtf works with svn like you say.
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
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Wesnoth Lua Pack: Development Thread

Post by 8680 »

I was looking through wml-tags.lua and saw that many of the tags could be streamlined, for example...
Example 1

Code: Select all

function wml_actions.store_shroud ( cfg )
	wesnoth.set_variable (
		cfg.variable or helper.wml_error "Missing required variable= attribute in [store_shroud].",
		wesnoth.get_side ( cfg.side or helper.wml_error "Missing required side= attribute in [store_shroud]" ).__cfg.shroud_data
	)
end
Instead of...

Code: Select all

function wml_actions.store_shroud(cfg)
	local team_number = cfg.side or helper.wml_error("Missing required side= attribute in [store_shroud]")
	local variable = cfg.variable or helper.wml_error("Missing required variable= attribute in [store_shroud].")
	local side = wesnoth.get_side(team_number)
	local current_shroud = side.__cfg.shroud_data
	wesnoth.set_variable(variable, current_shroud)
end
Example 2

Code: Select all

function wml_actions.flash_color ( cfg )
	flash (
		tonumber ( cfg.red ) or helper.wml_error "[flash_color] is missing required red= attribute",
		tonumber ( cfg.green ) or helper.wml_error "[flash_color] is missing required green= attribute",
		tonumber ( cfg.blue ) or helper.wml_error "[flash_color] is missing required blue= attribute"
	)
end
Instead of...

Code: Select all

function wml_actions.flash_color(cfg)
	local red = tonumber(cfg.red) or helper.wml_error("[flash_color] is missing required red= attribute")
	local green = tonumber(cfg.green) or helper.wml_error("[flash_color] is missing required green= attribute")
	local blue = tonumber(cfg.blue) or helper.wml_error("[flash_color] is missing required blue= attribute")

	flash( red, green, blue )
end
Just trying to help, I hope you don't mind....
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus »

This is a rather philosophic issue...
Using more variables makes the code more readable and easier to debug for sure. Also, I wonder whether the lua interpreter is so intelligent to do such conversion automatically. Modern java compilers do that at least I hear.
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
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Wesnoth Lua Pack: Development Thread

Post by 8680 »

Anonymissimus wrote:Using more variables makes the code more readable and easier to debug for sure.
Hm, for me it's the opposite....
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus »

Have you been working with a debugger ? In such long calls you cannot hover your mouse over a variable to see what it's value is to hunt down the erroneous position.
Similar if you use debug messages or log domains, you need a variable to put into the 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
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Wesnoth Lua Pack: Development Thread

Post by 8680 »

If I need to use the value more than once I'd use a variable, but in those examples each variable was only used once.... Meh. It's not my code, I'll leave.
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 »

However, this made me think that I can modify [store_shroud] to have some default values instead of raising errors (untested):

Code: Select all

function wml_actions.store_shroud(cfg)
	local team_number = tonumber ( cfg.side ) or 1 -- if missing or wrong, default to side 1
	local variable = cfg.variable or "shroud" -- if missing, default to shroud as variable name
	local side = wesnoth.get_side(team_number)
	local current_shroud = side.__cfg.shroud_data
	wesnoth.set_variable(variable, current_shroud)
end
Anything against it?
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)
AI
Developer
Posts: 2396
Joined: January 31st, 2008, 8:38 pm

Re: Wesnoth Lua Pack: Development Thread

Post by AI »

Please read this mailinglist thread before proceeding. There's some discussion about defaults, whether we should have them and what they should be in there. (brought up by the lua-conversion of some tags changing the defaults)
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.2.0 of the WLP is on the 1.9 add-ons server and on UMC-dev on Sourceforge. This release includes two new tags: [animate_path] by Alarantalara and [find_path] by me. It includes also a WLP_VERSION macro by Anonymissimus.
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