Extensions Object API

The MMFI Object API is a an alternative to the established MMF Interface API built into XLua.  Instead of a set of static functions that operate on object IDs, objects exist as their own object table, with their own functions and values.  This design is currently experimental and feedback to the developer is welcome.

Each object exists as a special Lua table with fields and functions.  These tables are special because they appear empty and functions like pairs and ipairs will return nothing.  However these tables track their own fixed IDs and object pointers, and accessing their values allow you to read and change an object's state in MMF directly.  Another benefit to these tables is that you can add your own fields and methods like with any other Lua table, and thus keep state and behavior with the object itself.

Object tables are also unique.  If you try to get or create a new table for the same object, a reference to the same table will be returned.

Traits

There are several groups of actions/conditions/expressions in MMF that are shared by many different objects in MMF.  Examples are movement, visibility, and alterable values.  The MMFI can determine at runtime which of these groups, if any, are supported by a particular object, and then expose fields and methods relating to them.  You can count on every object at least supporting the common traits, although they may support others.  The traits are:

Supported Objects

All objects are supported by the MMFI, by exposing a combination of the traits listed above.  There is also additional support for some objects, exposing fields or methods that are specific to a particular type of object.  Currently these are:

Third party modules can add specific support for other objects.

Example

-- These IDs represent fixed IDs of two objects
OBJ1 = 1234
OBJ2 = 5678
 
-- Create the two objects
object1 = mmf.newObject(OBJ1)
object2 = mmf.newObject(OBJ2)
 
-- Move object1 up and over 50 pixels
object1.x = object1.x + 50
object1.y = object1.y + 50
 
-- Check that object1 is above object2, and change its
-- ordering if needed
if not object1.isAbove(object2) then
  object1.moveAbove(object2)
end
 
-- Print object2's third flag
print(object2.flags[2])


See also:
     Display Traits, Common Traits, Movement Traits, Animation Traits, Value Traits, Object Classes, New Object

Copyright 2010 Justin Aquadro