/*****************************************************************************
 * $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/dyna.hh"
using namespace object;
#include "game/module.hh"
#include "game/missile.hh"
using namespace game;
#include "lua_bind/module.hh"
#include "lua_bind/bind.hh"

namespace lua {


namespace bind {

#define BIND_CLASS_NAME      "Missile"
#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
CheckTypesigMissile( shptr<Missile> obj )
{
    CHECK_TYPESIG(obj,TYPESIG_MISSILE);
}
#endif // ! DOXYGEN

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

        return DESTROY_USERDATA_SHPTR<Missile>( L, CheckTypesigMissile );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * table Missile:GetMatrix()
 *****************************************************************************/
INTERN int 
Missile_GetMatrix( lua_State* L ) 
{ 
   try { 

        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        PUSH_TABLE_FROM_MATRIX( L, missile->GetMatrix() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * string Missile:GetName()
 *****************************************************************************/
INTERN int 
Missile_GetName( lua_State* L ) 
{ 
   try { 

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

/*****************************************************************************
 * Vec3 Missile:GetPosition()
 *****************************************************************************/
INTERN int 
Missile_GetPosition( lua_State* L ) 
{ 
   try { 

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

/*****************************************************************************
 * number Missile:GetRawPtr()
 *****************************************************************************/
INTERN int 
Missile_GetRawPtr( lua_State* L ) 
{ 
   try { 

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

/*****************************************************************************
 * bool Missile:IfCollidable()
 *****************************************************************************/
INTERN int 
Missile_IfCollidable( lua_State* L ) 
{ 
   try { 

        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        lua_pushboolean( L, missile->IfCollidable() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool Missile:IfCollision()
 *****************************************************************************/
INTERN int 
Missile_IfCollision( lua_State* L ) 
{ 
   try { 

        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        lua_pushboolean( L, missile->IfCollision() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool Missile:IfCollisionFatal()
 *****************************************************************************/
INTERN int 
Missile_IfCollisionFatal( lua_State* L ) 
{ 
   try { 

        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        lua_pushboolean( L, missile->IfCollisionFatal() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool Missile:IfZombie()
 *****************************************************************************/
INTERN int 
Missile_IfZombie( lua_State* L ) 
{ 
   try { 

        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        lua_pushboolean( L, missile->IfZombie() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Missile:New( target, launcher, launcherSpeed, radiusGeo, malfunction )
 *****************************************************************************/
INTERN int 
Missile_New( lua_State* L ) 
{ 
   try { 

        const bool malfunction        = POP_BOOL( L );
        const Meter particleRadiusGeo = Meter( POP_FP( L ) );
        const Speed launcherSpeed     = Speed( POP_FP( L ) );
        shptr<Dyna> launcher          = POP_USERDATA_AS_SHPTR<Dyna>( L );
        shptr<Dyna> target            = POP_USERDATA_AS_SHPTR<Dyna>( L );
        CHECK_TYPESIG(launcher,TYPESIG_OBJECT);
        CHECK_TYPESIG(target,TYPESIG_OBJECT);
        shptr<Missile> missile = new Missile( target, *launcher, launcherSpeed, particleRadiusGeo, malfunction );
        return NEW_USERDATA_SHPTR<Missile>( L, missile, BIND_METATABLE_NAME );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Missile:Reset()
 *****************************************************************************/
INTERN int 
Missile_Reset( lua_State* L ) 
{ 
   try { 

        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        missile->Reset();
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Missile:Rotate( axis, radian )
 *****************************************************************************/
INTERN int 
Missile_Rotate( lua_State* L ) 
{ 
   try { 

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

/*****************************************************************************
 * Missile:SetCollidable( bool )
 *****************************************************************************/
INTERN int 
Missile_SetCollidable( lua_State* L ) 
{ 
   try { 

        const bool f = POP_BOOL( L );
        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        missile->SetCollidable( f );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Missile:SetCollision( int )
 *****************************************************************************/
INTERN int 
Missile_SetCollision( lua_State* L ) 
{ 
   try { 

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

/*****************************************************************************
 * Missile:SetMatrix( matrix )
 *****************************************************************************/
INTERN int 
Missile_SetMatrix( lua_State* L ) 
{ 
   try { 

        Matrix m; POP_TABLE_INTO_MATRIX( L, m );
        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        missile->SetMatrix( m, Missile::PLACEMENT );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

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

        const WorldVertex pos = POP_VECTOR3<WorldVertex>( L );
        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        missile->SetPosition( pos );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * Missile:Zombify()
 *****************************************************************************/
INTERN int 
Missile_Zombify( lua_State* L ) 
{ 
   try { 

        shptr<Missile> missile = POP_USERDATA_AS_SHPTR<Missile>( L );
        CHECK_TYPESIG(missile,TYPESIG_MISSILE);
        missile->Zombify();
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

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

#if ! DOXYGEN 

INTERN const struct luaL_reg sMethodTable[] =
{
  { "New", Missile_New },
  { "__gc", Missile_Destroy },
  { "GetMatrix", Missile_GetMatrix },
  { "GetName", Missile_GetName },
  { "GetPosition", Missile_GetPosition },
  { "GetRawPtr", Missile_GetRawPtr },
  { "IfCollidable", Missile_IfCollidable },
  { "IfCollision", Missile_IfCollision },
  { "IfCollisionFatal", Missile_IfCollisionFatal },
  { "IfZombie", Missile_IfZombie },
  { "Reset", Missile_Reset },
  { "Rotate", Missile_Rotate },
  { "SetCollidable", Missile_SetCollidable },
  { "SetCollision", Missile_SetCollision },
  { "SetMatrix", Missile_SetMatrix },
  { "SetPosition", Missile_SetPosition },
  { "Zombify", Missile_Zombify },
  { NULL, NULL }
};

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

#endif // ! DOXYGEN 

} // namespace bind 

} // namespace lua 
