Sigurd's Lua Questions
Moderator: Forum Moderators
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Sigurd's Lua Questions
Here's my thread for the occasional lua questions that I just can't seem to figure out how to find the answer.
Here's the first one:
Here's the first one:
Code: Select all
-- #textdomain wesnoth-My_Add-on
_ = wesnoth.textdomain "wesnoth-My_Add-on"
str1 = _ "This will be marked for translation."
str2 = _ [[Will Double Brackets get marked for translation?]]
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
Re: Sigurd's Lua Questions
In short, yes. The underscore is really a function name, and your double-bracket string gets passed as an argument to that function, so it should work fine.
(Unless I totally misunderstand how translations work. )
EDIT: Actually, I think a separate program has to parse the Lua file to find out which strings need to be translated. That program might not understand double-bracket strings, so I'm not qualified to answer that question.
(Unless I totally misunderstand how translations work. )
EDIT: Actually, I think a separate program has to parse the Lua file to find out which strings need to be translated. That program might not understand double-bracket strings, so I'm not qualified to answer that question.
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Sigurd's Lua Questions
Indeed, and that program is called wmlxgettext. It's available here: http://svn.gna.org/viewcvs/wesnoth/trun ... iew=markup , and it supports only '' and "" strings, not [[]] strings (but someone that, unlike me, knows Perl can check it and correct me).Luther wrote:I think a separate program has to parse the Lua file to find out which strings need to be translated.
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: Sigurd's Lua Questions
I know Perl, and I’d say it’s not just a question of whether one knows Perl, but also whether one has the patience to read a bunch of code that wasn’t written with maintainability in mind. People really should use the x regex flag more often.
Either way it seems (given line 144) it doesn’t support double-bracketed strings and assumes the text within, and the inner brackets are part of a WML tag specification, so it’d probably get confused in practice. (EDIT: correction: double-bracketed text will be simply ignored, apparently.)
This isn’t surprising in the least, as the script doesn’t seem to have received any significant changes since Lua support appeared in 1.7.x (commit log here).
It also appears to have unused, mostly commented out code intending to handle [attack] as a special case for some reason.
Either way it seems (given line 144) it doesn’t support double-bracketed strings and assumes the text within, and the inner brackets are part of a WML tag specification, so it’d probably get confused in practice. (EDIT: correction: double-bracketed text will be simply ignored, apparently.)
This isn’t surprising in the least, as the script doesn’t seem to have received any significant changes since Lua support appeared in 1.7.x (commit log here).
Code: Select all
while (m,\[ *([a-z/+].*?) *\],g) {
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Re: Sigurd's Lua Questions
A new lua question, this one about wesnoth.synchronize_choice in 1.11.8
I'm running the the following, which is just the wiki wesnoth.show_dialog example put in a function wrapper to use with wesnoth.synchronize_choice.
I've done it both from wesnoth.dofile & from functions loaded from wesnoth.require in my scripts
I keep getting:
<Lua error> Attempt to call a table value
in stack traceback
I'm running the the following, which is just the wiki wesnoth.show_dialog example put in a function wrapper to use with wesnoth.synchronize_choice.
I've done it both from wesnoth.dofile & from functions loaded from wesnoth.require in my scripts
Code: Select all
function sync_dialog()
local helper = wesnoth.require "lua/helper.lua"
local T = helper.set_wml_tag_metatable {}
local _ = wesnoth.textdomain "wesnoth"
local dialog = {
T.tooltip { id = "tooltip_large" },
T.helptip { id = "tooltip_large" },
T.grid { T.row {
T.column { T.grid {
T.row { T.column { horizontal_grow = true, T.listbox { id = "the_list",
T.list_definition { T.row { T.column { horizontal_grow = true,
T.toggle_panel { T.grid { T.row {
T.column { horizontal_alignment = "left", T.label { id = "the_label" } },
T.column { T.image { id = "the_icon" } }
} } }
} } }
} } },
T.row { T.column { T.grid { T.row {
T.column { T.button { id = "ok", label = _"OK" } },
T.column { T.button { id = "cancel", label = _"Cancel" } }
} } } }
} },
T.column { T.image { id = "the_image" } }
} }
}
local function preshow()
local t = { "Ancient Lich", "Ancient Wose", "Elvish Avenger" }
local function select()
local i = wesnoth.get_dialog_value "the_list"
local ut = wesnoth.unit_types[t[i]].__cfg
wesnoth.set_dialog_value(string.gsub(ut.profile, "([^/]+)$", "transparent/%1"), "the_image")
end
wesnoth.set_dialog_callback(select, "the_list")
for i,v in ipairs(t) do
local ut = wesnoth.unit_types[v].__cfg
wesnoth.set_dialog_value(ut.name, "the_list", i, "the_label")
wesnoth.set_dialog_value(ut.image, "the_list", i, "the_icon")
end
wesnoth.set_dialog_value(2, "the_list")
select()
end
local li = 0
local function postshow()
li = wesnoth.get_dialog_value "the_list"
end
local r = wesnoth.show_dialog(dialog, preshow, postshow)
wesnoth.message(string.format("Button %d pressed. Item %d selected.", r, li))
return { return_value = li }
end
function nil_func()
return { return_value = 0, dummy_value = "test" }
end
local q = wesnoth.synchronize_choice(sync_dialog(), nil_func())
local index = q.return_value
<Lua error> Attempt to call a table value
in stack traceback
: in function synchronize_choice
etc...
Originally, I had the line 'return { return_value = li }' as 'return li', then it complained about 'Attempt to call a number value'
So I read the wiki on wesnoth.synchronize_choice, wesnoth.show_dialog, & some forum posts.
From those documents, it looks like my example should work.
So, what am I doing wrong?
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
- Alarantalara
- Art Contributor
- Posts: 786
- Joined: April 23rd, 2010, 8:17 pm
- Location: Canada
Re: Sigurd's Lua Questions
The thing that immediately comes to mind is this:
You're calling your functions and passing the results, not passing the functions (unlike the example in the wiki).
Try
Instead.
Code: Select all
local q = wesnoth.synchronize_choice(sync_dialog(), nil_func())
Try
Code: Select all
local q = wesnoth.synchronize_choice(sync_dialog, nil_func)
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Re: Sigurd's Lua Questions
That was it, thanks.
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.