Next: 2.3.2.1 Generic LuaCOM objects
Up: 2.3 ActiveX binding
Previous: 2.3.1 Implementing dispinterfaces in
  Contents
The ActiveX interfaces have two ``types'' of members: properties and
methods. LuaCOM deals with both.
Method accesses are done in the same way as calling Lua functions
stored in a table and having a ``self'' parameter:
obj = luacom.CreateObject("TEST.Test")
if obj == nil then
exit(1)
end
-- method call
a = obj:Teste(1,2)
-- another one
obj:Teste2(a+1)
It's important to notice the need of using the colon - ``:'' - for
method calls. Although LuaCOM does not use the self
parameter that Lua passes in this case, its presence is assumed,
that is, LuaCOM always skips the first parameter in the case of
method calls; forgetting it may cause nasty bugs.
Accessing properties is much like the same of accessing fields in
Lua tables:
obj = luacom.CreateObject("TEST.Test")
if obj == nil then
exit(1)
end
-- property access
a = obj.TestData
-- property setting
obj.TestData = a + 1
Properties may also be accessed as methods. This is mandatory when
dealing with parameterized properties, that it, ones that accept (or
demand) parameters. A common example of this situation is the ``Item''
property of collections.
-- property access
a = obj:TestData()
-- Parametrized property access
b = obj:TestInfo(2)
-- Accessing collections
c = obj.Files:Item(2)
Notice that the colon - ``:'' - must also be used in this situation.
When accessing properties with method calls, LuaCOM always
translates the method call to a read access (property get). To set the
value of a property using a method call, it's necessary append the
prefix ``set''2.2 to the property name and the new value must be
supplied as the last argument.
-- property access
a = obj:TestData()
-- Setting the property
b = obj:setTestInfo(2)
-- Setting a parametrized property
c = obj.Files:setItem(2, "test.txt")
The prefix ``get'' may also be used, to clarify the code, although
it's not necessary, as the default behavior is to make a read access.
-- property access
a = obj:getTestData()
b = obj:getTestInfo(2)
c = obj.Files:getItem(2)
Subsections
Next: 2.3.2.1 Generic LuaCOM objects
Up: 2.3 ActiveX binding
Previous: 2.3.1 Implementing dispinterfaces in
  Contents
Vinicius da Silva Almendra
2003-06-27