/*****************************************************************************
 * $LastChangedDate: 2011-03-17 19:59:52 -0400 (Thu, 17 Mar 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Interface of C functions for Lua scripts.
 * @remarks @remarks module.txt documents how to export new C++ classes to Lua.
 *
 * ----------------------------
 * -- THIS IS AUTO-GENERATED --
 * ----------------------------
 *
 *//*
 * LEGAL:   COPYRIGHT (C) 2008 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#include "base/module.hh"
using namespace base;
#include "object/module.hh"
#include "object/aircraft.hh"
using namespace object;
#include "program/module.hh"
#include "program/carrier.hh"
using namespace program;
#include "lua_bind/module.hh"
#include "lua_bind/bind.hh"

namespace lua {


namespace bind {

#define BIND_CLASS_NAME      "Carrier"
#define BIND_METATABLE_NAME  LUABIND_METATABLE_STRING(BIND_CLASS_NAME)

//==============================================================================
// C functions called by Lua that access C++ objects.
//==============================================================================
// Need a function to check typesig because of macro/template limitations.
#if ! DOXYGEN
INTERN void
CheckTypesigCarrier( shptr<Carrier> obj )
{
    CHECK_TYPESIG(obj,TYPESIG_CARRIER);
}
#endif // ! DOXYGEN

/*****************************************************************************
 * Lua's garbage collector indirectly invokes this C++ destructor.
 *****************************************************************************/
INTERN int 
Carrier_Destroy( lua_State* L ) 
{ 
   try { 

        return DESTROY_USERDATA_SHPTR<Carrier>( L, CheckTypesigCarrier );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * table Carrier:GetMatrix()
 *****************************************************************************/
INTERN int 
Carrier_GetMatrix( lua_State* L ) 
{ 
   try { 

        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        PUSH_TABLE_FROM_MATRIX( L, carrier->GetMatrix() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * string Carrier:GetName()
 *****************************************************************************/
INTERN int 
Carrier_GetName( lua_State* L ) 
{ 
   try { 

        Carrier* carrier = POP_USERDATA_AS_SHPTR<Carrier>( L ).PTR();
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        lua_pushstring( L, carrier->GetName().c_str() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Vec3 Carrier:GetPosition()
 *****************************************************************************/
INTERN int 
Carrier_GetPosition( lua_State* L ) 
{ 
   try { 

        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        const WorldVertex pos = carrier->GetPosition();
        PUSH_VECTOR3( L, pos );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * number Carrier:GetRawPtr()
 *****************************************************************************/
INTERN int 
Carrier_GetRawPtr( lua_State* L ) 
{ 
   try { 

        Carrier* carrier = POP_USERDATA_AS_SHPTR<Carrier>( L ).PTR();
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        lua_pushnumber( L, long(static_cast<Carrier*>(carrier)) );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool Carrier:IfCollidable()
 *****************************************************************************/
INTERN int 
Carrier_IfCollidable( lua_State* L ) 
{ 
   try { 

        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        lua_pushboolean( L, carrier->IfCollidable() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool Carrier:IfCollision()
 *****************************************************************************/
INTERN int 
Carrier_IfCollision( lua_State* L ) 
{ 
   try { 

        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        lua_pushboolean( L, carrier->IfCollision() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool Carrier:IfCollisionFatal()
 *****************************************************************************/
INTERN int 
Carrier_IfCollisionFatal( lua_State* L ) 
{ 
   try { 

        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        lua_pushboolean( L, carrier->IfCollisionFatal() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool Carrier:IfZombie()
 *****************************************************************************/
INTERN int 
Carrier_IfZombie( lua_State* L ) 
{ 
   try { 

        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        lua_pushboolean( L, carrier->IfZombie() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Carrier:New( x,y,z|Vec, carrierNum )
 *****************************************************************************/
INTERN int 
Carrier_New( lua_State* L ) 
{ 
   try { 

        const int         carrierNum = POP_INT( L );
        const WorldVertex carrierPos = POP_VECTOR3<WorldVertex>( L );
        shptr<Carrier> carrier = Carrier::MakeCarrier( carrierPos, carrierNum );
        return NEW_USERDATA_SHPTR<Carrier>( L, carrier, BIND_METATABLE_NAME );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Carrier:PlaceAircraft( aircraft, meterX,meterY,meterZ|Vec3 )
 *****************************************************************************/
INTERN int 
Carrier_PlaceAircraft( lua_State* L ) 
{ 
   try { 

        const GeoVertex geoPos   = POP_VECTOR3<GeoVertex>( L );
        shptr<Aircraft> aircraft = POP_USERDATA_AS_SHPTR<Aircraft>( L );
        shptr<Carrier>  carrier  = POP_USERDATA_AS_SHPTR<Carrier>( L );   // self
        CHECK_TYPESIG(aircraft,TYPESIG_AIRCRAFT);
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        carrier->PlaceAircraft( aircraft, geoPos );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Carrier:Reset()
 *****************************************************************************/
INTERN int 
Carrier_Reset( lua_State* L ) 
{ 
   try { 

        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        carrier->Reset();
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Carrier:Rotate( axis, radian )
 *****************************************************************************/
INTERN int 
Carrier_Rotate( lua_State* L ) 
{ 
   try { 

        const fp   radian = POP_FP( L );
        const uint axis   = POP_INT( L );
        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        carrier->Rotate( axis, radian );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Carrier:SetCollidable( bool )
 *****************************************************************************/
INTERN int 
Carrier_SetCollidable( lua_State* L ) 
{ 
   try { 

        const bool f = POP_BOOL( L );
        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        carrier->SetCollidable( f );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Carrier:SetCollision( int )
 *****************************************************************************/
INTERN int 
Carrier_SetCollision( lua_State* L ) 
{ 
   try { 

        const int collision = POP_INT( L );
        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        carrier->SetCollision( static_cast<Carrier::eCollision>( collision ) );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Carrier:SetMatrix( matrix )
 *****************************************************************************/
INTERN int 
Carrier_SetMatrix( lua_State* L ) 
{ 
   try { 

        Matrix m; POP_TABLE_INTO_MATRIX( L, m );
        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        carrier->SetMatrix( m, Carrier::PLACEMENT );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Carrier:SetPosition( x,y,z|Vec3 )
 *****************************************************************************/
INTERN int 
Carrier_SetPosition( lua_State* L ) 
{ 
   try { 

        const WorldVertex pos = POP_VECTOR3<WorldVertex>( L );
        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        carrier->SetPosition( pos );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Carrier:Zombify()
 *****************************************************************************/
INTERN int 
Carrier_Zombify( lua_State* L ) 
{ 
   try { 

        shptr<Carrier> carrier = POP_USERDATA_AS_SHPTR<Carrier>( L );
        CHECK_TYPESIG(carrier,TYPESIG_CARRIER);
        carrier->Zombify();
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

//==============================================================================
// Register binding with Lua. 
//==============================================================================

#if ! DOXYGEN 

INTERN const struct luaL_reg sMethodTable[] =
{
  { "New", Carrier_New },
  { "__gc", Carrier_Destroy },
  { "GetMatrix", Carrier_GetMatrix },
  { "GetName", Carrier_GetName },
  { "GetPosition", Carrier_GetPosition },
  { "GetRawPtr", Carrier_GetRawPtr },
  { "IfCollidable", Carrier_IfCollidable },
  { "IfCollision", Carrier_IfCollision },
  { "IfCollisionFatal", Carrier_IfCollisionFatal },
  { "IfZombie", Carrier_IfZombie },
  { "PlaceAircraft", Carrier_PlaceAircraft },
  { "Reset", Carrier_Reset },
  { "Rotate", Carrier_Rotate },
  { "SetCollidable", Carrier_SetCollidable },
  { "SetCollision", Carrier_SetCollision },
  { "SetMatrix", Carrier_SetMatrix },
  { "SetPosition", Carrier_SetPosition },
  { "Zombify", Carrier_Zombify },
  { NULL, NULL }
};

void
RegisterCarrier( lua_State* L )
{
    REGISTER_BINDING( L,
                      BIND_METATABLE_NAME,
                      BIND_CLASS_NAME,
                      sMethodTable );
}

#endif // ! DOXYGEN 

} // namespace bind 

} // namespace lua 
