lua-users home
lua-l archive

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


I am using Lua 4.0.

I have some userdata implemented in 'C' that has a "gettable" tag method on it. 

One of the data items in the user data can be either a data 
access where a value is pushed onto the Lua stack via lua_pushnumber,
lua_pushstring, etc.) 
or a function access (which pushes a 'C' or Lua function on the Lua stack via
lua_pushfunction, etc.). 

To illustrate this please consider the following Lua code fragment:

function callAdd(userdata)
    local dataitem = userdata.Add
end

where the gettable tag method is called to return a data object using index
'Add'

and

function callAdd(userdata)
    local dataitem = userdata:Add()
end

where the gettable tag method is called to return a function object.  The
function object index is 'Add'

I would like data access to occur when using the '.' syntax and a function
access to occur 
when using the ':' syntax (the current Lua opcode being executed is either 
OP_GETDOTTED or OP_PUSHSELF).

In each case the gettable tag method is called with the userdata and the index
name as parameters.
The tag method is written in 'C'.

My question is this: is there any way to determine from the tag method whether
the data object or the
function object should be returned from the tag method. I am unable to change
the name of the
index to eliminate the ambiguity. I have considered adding a suffix or prefix to
the index name to 
eliminate the ambiguity but would rather not as it seems too big a hack to me.

Thanks,
Paul.