lua-users home
lua-l archive

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

I'm putting together an interface between Lua and Microsoft's COM Automation
system - it's not very robust yet, but it's a working proof of concept.

One thing I'm finding difficult, though, is mapping the very rich set of
automation-compatible datatypes onto Lua's relatively limited set of built
in types.

The big problem is the fact that I am converting a VARIANT type to a Lua
type "too early" - in other words, as soon as I get it back from the OS. I
think what I need to do is to encapsulate the variant as a userdata type.

This would be fine, but I'm somewhat stumped by the need to make VARIANTs
"act like" built in types when it is appropriate. The list of available tag
methods doesn't seem enough...

I can make variants "act like" numbers by defining add/sub/mul/div/unm tag
methods - but that's a lot of duplication, when all I do is convert the
variant to a number (handling errors if necessary) and then fall back to the
numeric operation. And it doesn't allow me to call (for example) log() from
the math library with a variant.

Same problem for strings - and worse, as there is only one tag method
relevant to strings, namely concat. Most of the useful stuff is done via

And worse still is the "boolean" contexts - I'd like to be able to have
variants of VT_BOOL type with a FALSE value test as false in if/while/etc
statements. But I can see no way at all of doing that...

Is there a good way of doing what I'm trying to achieve?

Paul Moore.