Re: Keyword as function name (was: Table dot number?)
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Keyword as function name (was: Table dot number?)
- From: Tomas Guisasola Gorham <tomas@...>
- Date: 2011年10月28日 18:43:11 -0200 (BRST)
Sometimes, you cannot avoid it. For example when generating a 1-1
binding to a library which uses methods named as Lua keywords. An
example of this is the Qt library - 19 of it's classes have a method
named 'end' [1], which you cannot call using Lua's syntax sugar. You
have to call it as follows:
painter['end'](painter)
Does someone propose an elegant way to handle this? :)
painter._end = painter['end']
You can use uppercase:
for k, v in pairs(painter) do
if type(k) == "string" and type(v) == "function" then
local K = k:gsub("^(.)", string.upper)
painter[K] = v
end
end
assert(painter['end'] == painter.End)
Or, if you prefer, do it only for the keywords...
Regards,
Tomás