3.3.4.1.2 com2lua situation

LuaCOM

next up previous contents Next: 3.3.4.1.3 Generic LuaCOM objects Up: 3.3.4.1 Calling COM from Previous: 3.3.4.1.1 lua2com situation   Contents

3.3.4.1.2 com2lua situation

When the called method finishes, LuaCOM translates the return value and the output values (that is, the values of the ``out'' and ``in-out'' parameters) to Lua return values. That is, the method return value is returned to the Lua code as the first return value; the output values are returned in the order they appear in the parameter list (notice that here we use the Lua feature of multiple return values). If the method does not have return values, that is, is a ``void'' method, the return values will be the output values. If there are no output values either, then there will be no return values.

The called method can omit the return value or the output values; LuaCOM them will return nil for each omitted value.

To illustrate these concepts, here follows a sample of these situations. First, we show an excerpt of an ODL file describing a method of a COM object:

  HRESULT TestShort(
    [in] short p1, // an "in" parameter
    [out] short* p2, // an "out" parameter
    [in,out] short* p3, // an "in-out" parameter
    [out,retval] short* retval); // the return value

Now follows a sample of what happens when calling the method:

-- assume that "com" is a LuaCOM object
-- Here we set p1 = 1, p3 = 2 and leave p2 uninitialized
-- When the method returns, r1 = retval and r2 = p2 and r3 = p3
r1, r2, r3 = com:TestShort(1,2)
-- WRONG! The are only two in/in-out parameters! Out parameters
-- are ignored in the lua2com parameter translation
r1, r2, r3 = com:TestShort(1,2,3) -- WRONG!
-- Here p1 = 1, p2 is uninitialized and p3 is omitted.
r1, r2, r3 = com:TestShort(1)
-- Here we ignore the output value p3
r1,r2 = com:TestShort(1)
-- Here we ignore all output values (including the return value)
com:TestShort(1,2)


next up previous contents
Next: 3.3.4.1.3 Generic LuaCOM objects Up: 3.3.4.1 Calling COM from Previous: 3.3.4.1.1 lua2com situation   Contents
Fabio Mascarenhas de Queiroz 2005-01-07