-- $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.
--
-- Common Object methods.
--
-- InheritMethod() is supposed to do string substitution of the code.
-- For example:
-- function InheritMethod( code )
--     code = string.gsub( code, "object", "dyna" )
--     code = string.gsub( code, "Object", "Dyna" )
--     code = string.gsub( code, "OBJECT", "DYNA" )
--     return code
-- end
-- dofile( "bind_object_common.lua" )
--
-- DO NOT FORGET TO USE InheritMethod() !!

bindTable.func_GetName = {
    comments = InheritMethod( "string Object:GetName()" ),
    code = InheritMethod( [[
        Object* object = POP_USERDATA_AS_SHPTR<Object>( L ).PTR();
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        lua_pushstring( L, object->GetName().c_str() );
        return 1;  // stack items to return
    ]] )
}

bindTable.func_Reset = {
    comments = InheritMethod( "Object:Reset()" ),
    code = InheritMethod( [[
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        object->Reset();
    ]] )
}

bindTable.func_SetPosition = {
    comments = InheritMethod( "Object:SetPosition( x,y,z|Vec3 )" ),
    code = InheritMethod( [[
        const WorldVertex pos = POP_VECTOR3<WorldVertex>( L );
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        object->SetPosition( pos );
    ]] )
}

bindTable.func_GetPosition = {
    comments = InheritMethod( "Vec3 Object:GetPosition()" ),
    code = InheritMethod( [[
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        const WorldVertex pos = object->GetPosition();
        PUSH_VECTOR3( L, pos );
        return 1;  // stack items to return
    ]] )
}

bindTable.func_Rotate = {
    comments = InheritMethod( "Object:Rotate( axis, radian )" ),
    code = InheritMethod( [[
        const fp   radian = POP_FP( L );
        const uint axis   = POP_INT( L );
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        object->Rotate( axis, radian );
    ]] )
}

bindTable.func_SetMatrix = {
    comments = InheritMethod( "Object:SetMatrix( matrix )" ),
    code = InheritMethod( [[
        Matrix m; POP_TABLE_INTO_MATRIX( L, m );
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        object->SetMatrix( m, Object::PLACEMENT );
    ]] )
}

bindTable.func_GetMatrix = {
    comments = InheritMethod( "table Object:GetMatrix()" ),
    code = InheritMethod( [[
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        PUSH_TABLE_FROM_MATRIX( L, object->GetMatrix() );
        return 1;  // stack items to return
    ]] )
}

bindTable.func_SetCollidable = {
    comments = InheritMethod( "Object:SetCollidable( bool )" ),
    code = InheritMethod( [[
        const bool f = POP_BOOL( L );
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        object->SetCollidable( f );
    ]] )
}

bindTable.func_SetCollision = {
    comments = InheritMethod( "Object:SetCollision( int )" ),
    code = InheritMethod( [[
        const int collision = POP_INT( L );
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        object->SetCollision( static_cast<Object::eCollision>( collision ) );
    ]] )
}

bindTable.func_IfCollidable = {
    comments = InheritMethod( "bool Object:IfCollidable()" ),
    code = InheritMethod( [[
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        lua_pushboolean( L, object->IfCollidable() );
        return 1;  // stack items to return
    ]] )
}

bindTable.func_IfCollision = {
    comments = InheritMethod( "bool Object:IfCollision()" ),
    code = InheritMethod( [[
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        lua_pushboolean( L, object->IfCollision() );
        return 1;  // stack items to return
    ]] )
}

bindTable.func_IfCollisionFatal = {
    comments = InheritMethod( "bool Object:IfCollisionFatal()" ),
    code = InheritMethod( [[
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        lua_pushboolean( L, object->IfCollisionFatal() );
        return 1;  // stack items to return
    ]] )
}

bindTable.func_Zombify = {
    comments = InheritMethod( "Object:Zombify()" ),
    code = InheritMethod( [[
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        object->Zombify();
    ]] )
}

bindTable.func_IfZombie = {
    comments = InheritMethod( "bool Object:IfZombie()" ),
    code = InheritMethod( [[
        shptr<Object> object = POP_USERDATA_AS_SHPTR<Object>( L );
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        lua_pushboolean( L, object->IfZombie() );
        return 1;  // stack items to return
    ]] )
}

bindTable.func_GetRawPtr = {
    comments = InheritMethod( "number Object:GetRawPtr()" ),
    code = InheritMethod( [[
        Object* object = POP_USERDATA_AS_SHPTR<Object>( L ).PTR();
        CHECK_TYPESIG(object,TYPESIG_OBJECT);
        lua_pushnumber( L, long(static_cast<Object*>(object)) );
        return 1;  // stack items to return
    ]] )
}
