3.4.4 Arrays and Tables

LuaCOM

next up previous contents Next: 3.4.5 CURRENCY type Up: 3.4 Type Conversion Previous: 3.4.3 Pointers to IUnknown   Contents

3.4.4 Arrays and Tables

If the table does not have a tocom tag method (for Lua 4) or __tocom metamethod (for Lua 5), LuaCOM first checks if the table can be describing a date. A table is a date if it has one of those fields: Day, DayOfWeek, Month, Year, Hour, Minute, Second, Milliseconds. LuaCOM initializes the date with the fields that are present; the others are kept at their default values.

If the table is not a date, LuaCOM converts Lua tables to SAFEARRAY's and vice-versa. To be converted, Lua tables must be ``array-like'', that is, all of its elements must be or ``scalars'' or tables of the same length. These tables must also be ``array-like''. Here are some samples of how is this conversion done:

Lua table Safe Array
table = {"name", "phone"}

\begin{displaymath} \left[\begin{array}{cc} ''name'' & ''phone'' \\ \end{array}\right] \end{displaymath}

table = {{1,2},{4,9}}

\begin{displaymath} \left[\begin{array}{cc} 1 & 2 \\ 4 & 9 \\ \end{array} \right] \end{displaymath}

If the table has the conversion tag/metamethod, LuaCOM uses it to guide the conversion. If the tag/metamethod is a method, LuaCOM calls it, passing the table and the COM type. The method should return a COM object that LuaCOM will pass on. If the tag/metamethod is a table, LuaCOM will look for a typelib field, an interfacefield , and a coclass field, and pass those as arguments to the ImplInterfaceFromTypelib API call. If the table does not have a typelib field, LuaCOM will look for a progid field and an interface field, and pass those to the ImplInterface API call. Either way, LuaCOM will pass the returned object to COM.


next up previous contents
Next: 3.4.5 CURRENCY type Up: 3.4 Type Conversion Previous: 3.4.3 Pointers to IUnknown   Contents
Fabio Mascarenhas de Queiroz 2005-01-07