lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

 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:


 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
assert(painter['end'] == painter.End)

	Or, if you prefer, do it only for the keywords...