lua-users home
lua-l archive

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


Say I am writing C code that wants to get and set properties with string values, the equivalent of:

    obj1.foo = 'optionA'
    obj2.foo = 'optionB'
    print(obj3.foo)

where in the C code, the strings like 'optionA' must be converted to values like ENUM_A. Typically, for a property I might have up to half a dozen values.

So for setting a property, I could manually get the argument as a string, and use strcmp to choose which enum value is being specified.

Or, I could just build a table where keys are strings and values are the enum values, and use that to lookup which enum value is being specified.

Which is generally preferred? Is there a better way?