lua-users home
lua-l archive

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


For my current project I have made lua bindings for a UI system. The
bulk of this consists of userdata types for panels, buttons, checkboxes
and other widgets, plus a bunch of factory methods. In order to simplify
menu creation and use, I am also creating a set of utility lua objects
that add functionality to the user data types. Which brings me to my
question.

In the C methods operating on the userdata, I can use luaL_checkudata to
verify that the userdata is the correct type. Is there any analogous way
to do this on the lua side? Just doing 'type(object) == "userdata"' is
not sufficient, since that doesnt distinguish a Button from any other
userdata type.

I can quite easily add "IsButton(x)" methods to the menu object, one for
each of the factory methods and implement them in C using
luaL_checkudata. I was just wondering if there is some simpler way first
to do this entirely in lua.

Do people generally do things like this to confirm that they have the
correct userdata type? Or do you just rely on the errors that arise when
non-existant table entries are accessed?

Maybe I am just having trouble letting go of my need for strong typing
:)

- DC