Simulator exports some functions and constants to the Mission Scripting Environment. All symbols are grouped in tables.
Simulator has many entities which behave like an objects and classes in terms of object-oriented languages. To make manipulation with such objects easer "class-object" relations were emulated in the Lua environement with metatables. This framework is located in ./Scripts/Common/LuaClass.Lua.
Lua-"class" is a table that has following structure:
Class = { static = { staticFunc1 = function(...) ... end, ... staticFuncN = function(...) ... end }, member = { memberFunc1 = function(objectID, ...) ... end, ... memberFuncM = function(objectID, ...) ... end }, className_ = "ClassName", parentClass_ = Class }
static
member
className_
parentClass_
Lua-"object" is a table that has following structure:
ObjectName = { id_ = ... }
id_
Objects of the same class have set the same metatable - the class table.
The framework allows single inheritance, but doesn't allow multiple inheritance. Table of base class must be value of parentClass_ field table of derivative class.
LuaClass table must be assigned as a metatable to all Lua-"classes". LuaClass does all the job when user uses Lua-"classes" and Lua-"objects". LuaClass.__index metamethod is a function that looks for function that user want to call in Lua-"class" that the Lua-"object" belongs to or in base "classes" and calls the function.
LuaClass has also useful several functions those may be called any Lua-"class".
function LuaClass.createFor(class, id_)
creates and returns Lua-"object" that belongs to class Lua-"class" and has identifier id_. No new entity created. The function just creates and initializies Lua-"object" table for existing entity.
function LuaClass.create(class, ...)
uses class.static.create function to create new entity and then uses LuaClass.createFor to create Lua-"object" class for just created entity.
function LuaClass.cast(class, object)
casts object to object of another class. Downcast must be unsafe if user will cast the object to class that object not realy belongs to.
function class(tbl, parent)
declares table tbl as a Lua-"class" and as a derrivative class of a parent if parent is not nil
Simulator exported some tables with functions and constants to the Mission Scripting Environment and then runs ./Scripts/MissionScripting.lua script do declare these tables a Lua-"classes".
However you may declare your own classes. To do it you must: