/*****************************************************************************
 * $LastChangedDate: 2011-03-15 14:18:37 -0400 (Tue, 15 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 "view/module.hh"
#include "view/viewpoint_otw.hh"
#include "view/observer_current_craft.hh"
using namespace view;
#include "lua_bind/module.hh"
#include "lua_bind/bind.hh"

namespace lua {


namespace bind {

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

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

        return DESTROY_USERDATA_SHPTR<OtwViewpoint>( L, CheckTypesigOtwViewpoint );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * OtwViewpoint:New(Observer)
 *****************************************************************************/
INTERN int 
OtwViewpoint_New( lua_State* L ) 
{ 
   try { 

        // Create OTW Viewpoint with Observer.
        shptr<Observer> observer = POP_USERDATA_AS_SHPTR<Observer>( L );
        CHECK_TYPESIG(observer,TYPESIG_OBSERVER);
        shptr<OtwViewpoint> viewpoint = new OtwViewpoint( observer );
        return NEW_USERDATA_SHPTR<OtwViewpoint>( L, viewpoint, BIND_METATABLE_NAME );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * OtwViewpoint:SetOtwMode( OTW_FRONT|REAR|LEFT|RIGHT )
 *****************************************************************************/
INTERN int 
OtwViewpoint_SetOtwMode( lua_State* L ) 
{ 
   try { 

        const OtwViewpoint::eOtwMode otwMode = static_cast<OtwViewpoint::eOtwMode>( POP_INT( L ) );
        shptr<OtwViewpoint> viewpoint = POP_USERDATA_AS_SHPTR<OtwViewpoint>( L );
        CHECK_TYPESIG(viewpoint,TYPESIG_OTW_VIEWPOINT);
        viewpoint->SetOtwMode( otwMode );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

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

#if ! DOXYGEN 

INTERN const struct luaL_reg sMethodTable[] =
{
  { "New", OtwViewpoint_New },
  { "__gc", OtwViewpoint_Destroy },
  { "SetOtwMode", OtwViewpoint_SetOtwMode },
  { NULL, NULL }
};

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

#endif // ! DOXYGEN 

} // namespace bind 

} // namespace lua 
