lua-users home
lua-l archive

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


On Saturday 17, Ezequiel García wrote:
> Hi Mark,
> 
> --- El sáb 17-dic-11, Mark Hamburg <mark@grubmah.com> escribió:
> > De: Mark Hamburg <mark@grubmah.com>
> > Asunto: Re: Lua binding: How to implement C enum
> > Para: "Lua mailing list" <lua-l@lists.lua.org>
> > Fecha: sábado, 17 de diciembre de 2011, 17:26
> > If worrying about speed, the answer
> > is probably to stash a table or two somewhere that can be
> > used to the string-to-enum and enum-to-string mappings. Say,
> > for example, that you define your mapping in C code as
> > something like (untested, uncompiled, written in e-mail,
> 
> > caveat, caveat, caveat):
> Well, you read my mind!!! I was thinking about the same thing.
> 
> Plus, for the return value, I thought on returning a userdata that
> implements a 'contanins()' function. So for the user, it looks simple
> enough:
> 
> s:SetCapabilities('ONE,TWO,THREE')
> 
> caps = s:GetCapabilities()
> 
> if caps:contains('ONE,TWO') then
>   -- stuff
> end

Use the contains function as the __index metamethod.
Then you would be able to use this syntax:

if caps['ONE,TWO'] then
  -- stuff
end

-- 
Robert G. Jakabosky