NAME ^

pmc/luatable.pmc - Lua Table

DESCRIPTION ^

LuaTable extends LuaBase to provide a class with the behaviour of the Lua Table type.

TRIVIAL IMPLEMENTATION : Table is just a Parrot Hash, like in Lua 4.0. Now, Lua 5.0 uses a hybrid data structure with a Hash part and an Array part.

Overloaded Methods ^

void init()

Initializes the instance.

void morph(INTVAL type)

Morphs the scalar to the specified type.

void mark()

Marks the hash as live.

void destroy()

Free hash structure.

STRING *name()

Return the string "table".

PMC *clone()

PMCs are always handled by-reference in Parrot. So, copying register contents only copies the reference to the PMC. For LuaString, LuaNumber, LuaBoolean, this is not correct, as Lua has by-value semantics for these types. In order to be able to handle register "move" instructions, this should be implemented using clone(). However, LuaTable and LuaFunction do have by-reference semantics. As you don't know the type during compile-time of an object, just always use clone() to copy register contents. LuaTable and LuaFunction should therefore only clone the reference to themselves, not make a deep copy.

STRING *get_string()

PMC *get_pmc_keyed (PMC *key)

table accessor.

A copy of the value is retrieved, otherwise, this could happen:

    temp = table[key]
    temp = <some other value>
    temp2 = table[key]
    # temp2 is now <some other value> due to the by-reference semantics of PMCs
void set_pmc_keyed (PMC *key, PMC *value)

table mutator.

A copy of the value is stored, otherwise, this could happen:

    table[key] = value
    value = <some other value>
    temp = table[key]
    # temp is now <some other value> due to the by-reference semantics of PMCs
INTVAL elements()

Returns the number of elements in the hash.

non-Vtable Methods ^

INTVAL is_equal (PMC *value)

The == operation. Compares reference (not in depth).

INTVAL cmp (PMC *value)

Specific Methods ^

PMC *get_metatable()

PMC *len()

PMC *next(PMC *index)

PMC *rawequal (PMC *value)

PMC *rawget (PMC *key)

void rawset (PMC *key, PMC *value)

void set_metatable(PMC *meta)

AUTHORS ^

Francois Perrad

Klaas-Jan Stol


parrot