-- $LastChangedDate: 2011-03-17 19:59:52 -0400 (Thu, 17 Mar 2011) $
-- Macros written in Lua to expand C++ code for bindings between C++/Lua.
-- Avoid lua_/LUA_ which is reserved by Lua.

bindTable = {

class = "Object",
typesig = "TYPESIG_OBJECT",
luaCanInstantiate = true,

headers =
[[
#include "base/module.hh"
using namespace base;
#include "object/module.hh"
#include "object/object.hh"
using namespace object;
#include "graph/module.hh"
#include "graph/model_cache.hh"
using namespace graph;
]],

func_New = {
    comments = "Object:New( x,y,z|Vec3, modelPathname, scale, ModelCache.LOAD_SHARED|LOAD_COPY )",
    code = [[
        const bool        loadCopy  = POP_BOOL( L );
        const fp          scale     = POP_FP( L );
        const string      modelName = POP_STRING( L );
        const WorldVertex pos       = POP_VECTOR3<WorldVertex>( L );

        // Load 3D model.
        shptr<Graph> graph = GET_MODEL_CACHE().LoadModel( modelName, scale, loadCopy );
        shptr<Object> object = new Object( graph, pos );

        return NEW_USERDATA_SHPTR<Object>( L, object, BIND_METATABLE_NAME );
    ]]
},

func_Destroy = {
    comments = "Lua's garbage collector indirectly invokes this C++ destructor.",
    code = [[
        return DESTROY_USERDATA_SHPTR<Object>( L, CheckTypesigObject );
    ]]
},

func_GetObjectCount = {
    comments = "int Object:GetObjectCount()",
    code = [[
        lua_pushnumber( L, Object::GetObjectCount() );
        return 1;  // stack items to return
    ]]
},

}

--------------------------------------------------------------------------------
-- Inherit Object methods.
function InheritMethod( code )
    return code
end
dofile( srcDir .. "/bind_object_common.lua" )
