next up previous contents
Next: 3.3.5 Exception Handling Up: 3.3.4 Parameter Passing Previous: 3.3.4.1.3 Generic LuaCOM objects   Contents

3.3.4.2 Calling Lua from COM

This situation happens when one implements a COM dispinterface in Lua. The ActiveX binding has to translate the COM method calls to Lua function calls. The policy here concerning parameter list translation is the same as the one above, just exchanging ``Lua'' for ``COM'' and vice-versa. That is, all ``in'' an ``in-out'' COM parameters are translated to parameters to the Lua function call (the output parameters are ignored). When the call finishes, the first return value is translated as the return value of the COM method and the other return values are translated as the ``in-out'' and ``out'' values, following the order they appear in the method's type information. Continuing the previous example, here we show the implementation of a method callable from COM:


implementation = {}

-- This method receives TWO in/in-out parameters
function implementation:TestShort(p1, p2)
  -- the first one is the retval, the second the first out param
  -- the third the second out param (in fact, an in-out param)
  return p1+p2, p1-p2, p1*p2
end

-- Implements an interface
obj = luacom.ImplInterface(implementation, "TEST.Test", ITest)

-- calls the function implementation:TestShort via COM
r1, r2, r3 = obj:TestShort(1,2)



Fabio Mascarenhas de Queiroz 2004-09-13