Wesnoth Lua Pack: Development Thread

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

Moderators: Forum Moderators, Developers

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

Re: Wesnoth Lua Pack: Development Thread

Post by monochromatic » March 12th, 2011, 5:00 am

wlp_tags.lua -> wml_tags.lua
For example.

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

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus » March 12th, 2011, 4:20 pm

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: 2458
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus » March 17th, 2011, 12:04 am

@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
Developer
Posts: 1375
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter » March 17th, 2011, 8:11 am

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:
1.14: The Sojournings of Grog, A Rough Life, The White Troll (co-author), Wesnoth Lua Pack
1.12: Children of Dragons
Active again until mid-October

User avatar
Alarantalara
Art Contributor
Posts: 782
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Wesnoth Lua Pack: Development Thread

Post by Alarantalara » March 17th, 2011, 12:46 pm

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
Developer
Posts: 1375
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter » March 18th, 2011, 2:43 pm

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:
1.14: The Sojournings of Grog, A Rough Life, The White Troll (co-author), Wesnoth Lua Pack
1.12: Children of Dragons
Active again until mid-October

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

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus » March 18th, 2011, 3:27 pm

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

Re: Wesnoth Lua Pack: Development Thread

Post by 8680 » March 28th, 2011, 6:01 pm

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: 2458
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus » March 28th, 2011, 9:58 pm

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

Re: Wesnoth Lua Pack: Development Thread

Post by 8680 » March 29th, 2011, 2:45 am

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: 2458
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Wesnoth Lua Pack: Development Thread

Post by Anonymissimus » March 29th, 2011, 3:19 pm

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

Re: Wesnoth Lua Pack: Development Thread

Post by 8680 » March 29th, 2011, 5:15 pm

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
Developer
Posts: 1375
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter » March 30th, 2011, 9:02 am

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:
1.14: The Sojournings of Grog, A Rough Life, The White Troll (co-author), Wesnoth Lua Pack
1.12: Children of Dragons
Active again until mid-October

AI
Developer
Posts: 2394
Joined: January 31st, 2008, 8:38 pm

Re: Wesnoth Lua Pack: Development Thread

Post by AI » March 30th, 2011, 9:27 am

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
Developer
Posts: 1375
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter » April 21st, 2011, 8:25 am

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:
1.14: The Sojournings of Grog, A Rough Life, The White Troll (co-author), Wesnoth Lua Pack
1.12: Children of Dragons
Active again until mid-October

Post Reply