ModularLua 0.5.1 - making Lua easier in Wesnoth
Moderator: Forum Moderators
ModularLua 0.5.1 - making Lua easier in Wesnoth
ModularLua 0.5.1 Features
Dialog creation
With Wesnoth's built-in dialog creation, there is a lot of flexibility. However, there's also a lot of boilerplate and room for mistakes, making even simple dialogs a pain and a half to set up. With ModularLua, you simply input a quick lua table representing the dialog, and it does the rest for you.
Event registration
Registering custom event handlers with Lua in Wesnoth involves overloading the wesnoth.game_events.on_event handler. You have to either overload it every time that you want to register a new event, or you have to have one central overload with a mess of if/then statements checking what the current event is. Again, a lot of boilerplate. ModularLua provides an event registry which maps event names to lists of functions to run for that event, making event handlers simple.
Pango markup generation
Generating pango markup is one of the more esoteric tasks in LuaWML. It looks like HTML, almost. But there's no way to easily generate the markup. It always has to be hand-crafted. This is mostly a concern when it comes to things which aren't easy to remember, like the bullet entity and text colors. ModularLua provides helper functions which wrap arbitrarily long lists of strings in appropriate markup.
Note: The markup library is geared more towards automatic pango generation. For longer, hard-coded text, you're probably better off just writing it by hand.
Scenario-level tag registration
This one's a little more abstract, since there's more than one way to do it - but if you ever tried this, I think you'll appreciate the difference that ModularLua makes. This code will allow [tag_name] as a scenario-level tag, will persist the tag across save/load cycles, and will allow the use of [tag_name] as an action tag to dynamically add new [tag_name] information from inside events.
By default, this tag will only store the configuration that was originally passed into it. You can add more behavior by overriding the init method of your new tag.
And more!
ModularLua cleans your dishes! Feeds your cat! Jumps up and down on your bed for you! Well, not really... but there are a lot of other things it does for you. Read the code to find out what. There is documentation in the code, though it's more complete in some places than in others. Also feel free to catch me on IRC in one of the #wesnoth channels if you have any questions.
Contributing
If you want to contribute, feel free to fork my repository on Github.
Bug reports/Feature Requests
I know that people generally like to put bug reports and feature requests in the forum, but it would be very helpful for me if you post them on Github so that I can keep track of them easier. To put it another way: I'll be less likely to forget!
Dialog creation
With Wesnoth's built-in dialog creation, there is a lot of flexibility. However, there's also a lot of boilerplate and room for mistakes, making even simple dialogs a pain and a half to set up. With ModularLua, you simply input a quick lua table representing the dialog, and it does the rest for you.
With Wesnoth:
With ModularLua:
Registering custom event handlers with Lua in Wesnoth involves overloading the wesnoth.game_events.on_event handler. You have to either overload it every time that you want to register a new event, or you have to have one central overload with a mess of if/then statements checking what the current event is. Again, a lot of boilerplate. ModularLua provides an event registry which maps event names to lists of functions to run for that event, making event handlers simple.
With Wesnoth:
With ModularLua:
Generating pango markup is one of the more esoteric tasks in LuaWML. It looks like HTML, almost. But there's no way to easily generate the markup. It always has to be hand-crafted. This is mostly a concern when it comes to things which aren't easy to remember, like the bullet entity and text colors. ModularLua provides helper functions which wrap arbitrarily long lists of strings in appropriate markup.
Note: The markup library is geared more towards automatic pango generation. For longer, hard-coded text, you're probably better off just writing it by hand.
With Wesnoth:
With ModularLua:
Scenario-level tag registration
This one's a little more abstract, since there's more than one way to do it - but if you ever tried this, I think you'll appreciate the difference that ModularLua makes. This code will allow [tag_name] as a scenario-level tag, will persist the tag across save/load cycles, and will allow the use of [tag_name] as an action tag to dynamically add new [tag_name] information from inside events.
With ModularLua:
Overriding init:
ModularLua cleans your dishes! Feeds your cat! Jumps up and down on your bed for you! Well, not really... but there are a lot of other things it does for you. Read the code to find out what. There is documentation in the code, though it's more complete in some places than in others. Also feel free to catch me on IRC in one of the #wesnoth channels if you have any questions.
Contributing
If you want to contribute, feel free to fork my repository on Github.
Bug reports/Feature Requests
I know that people generally like to put bug reports and feature requests in the forum, but it would be very helpful for me if you post them on Github so that I can keep track of them easier. To put it another way: I'll be less likely to forget!
Last edited by melinath on November 2nd, 2011, 9:04 am, edited 1 time in total.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: ModularLua - making things easier in 1.9
As a general comment - why do you set up and use your own repository ? The wesnoth umc repository is basically exactly the same as what you have there.
In case you need time for your real life or whatever someone else could keep your projects alive. And one can learn from the other coders.
(Ah ok, you seem to have non-wesnoth related stuff there, while the umc repo is no general purpose repository. Yet for wesnoth stuff it would make more sense...)
In case you need time for your real life or whatever someone else could keep your projects alive. And one can learn from the other coders.
(Ah ok, you seem to have non-wesnoth related stuff there, while the umc repo is no general purpose repository. Yet for wesnoth stuff it would make more sense...)
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: ModularLua - making things easier in 1.9
That's a fair question. There's a couple things going on here:
Edit:: Also, having just made my sourceforge account - it wants to know my job title and "number of employees", which I just find bizarre and unnecessarily complicated.
- Github is prettier than the Wesnoth-umc-dev
- Github uses git, which I know how to use, rather than svn, which I know how to check out repositories with.
- Github lets anyone who's interested make an account and fork the repository, rather than requiring that in addition you apply to be able to fork. (Of course the application for umc dev isn't hard core or anything, but it's another step.) So even if I need time in my life, other coders will still be able to carry the project on.
- I find the idea of having a single repository for multiple projects very strange. (Though I am willing to accept that this may be that I am just lacking in experience of one kind or another.)
- My impression is that UMC-dev has a single repository that everyone edits, and that the edits are immediately accepted. I prefer the model of forks and branches which are later merged together.
- Did I mention that github is pretty? I mean, it's gorgeous! Best feature (I think) is the network graphs, which show you all the branches, merges and commits for every user who has forked the repository.
- Also (part of being pretty) it's very user-friendly.
Edit:: Also, having just made my sourceforge account - it wants to know my job title and "number of employees", which I just find bizarre and unnecessarily complicated.
Re: ModularLua - making things easier in 1.9
ModularLua 0.5
I've uploaded v0.5 of ModularLua to the add-on server. Along with various bugfixes, it adds the following new features:
I've uploaded v0.5 of ModularLua to the add-on server. Along with various bugfixes, it adds the following new features:
- Added modular.dofile to match modular.require
- Added inspection and debug modules that make it easy to look at lua and wml objects.
- Added a debug shell which, thanks to recent work by Exasperation, can include a working shell history (unlike the shell posted here).
Re: ModularLua - making things easier in 1.9
ModularLua 0.5.1
Version 0.5.1 of ModularLua is up on the add-on server. I came back from a hiatus and discovered I was getting some pretty silly errors. These have been corrected, along with some enhancements and improved event documentation. The full changelog is:
Version 0.5.1 of ModularLua is up on the add-on server. I came back from a hiatus and discovered I was getting some pretty silly errors. These have been corrected, along with some enhancements and improved event documentation. The full changelog is:
0.5.1
=====
* events.register now takes a single event name as its first argument and a
function as its second argument.
* scenario-level tags created with the events framework are now guaranteed to be
processed by the framwork in the same order in which they were registered.
* small bugfixes and typo corrections.
* improved documentation of the events module.