/*****************************************************************************
 * $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 "view/module.hh"
#include "view/window.hh"
using namespace view;
#include "lua_bind/module.hh"
#include "lua_bind/bind.hh"

namespace lua {


namespace bind {

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

//==============================================================================
// C functions called by Lua that access C++ objects.
//==============================================================================

/*****************************************************************************
 * Window:GetFPS()
 *****************************************************************************/
INTERN int 
Window_GetFPS( lua_State* L ) 
{ 
   try { 

        lua_pushnumber( L, GET_WINDOW().GetFPS() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * View Window:GetMainView()
 *****************************************************************************/
INTERN int 
Window_GetMainView( lua_State* L ) 
{ 
   try { 

        shptr<View> view = GET_WINDOW().GetMainView();
        return NEW_USERDATA_SHPTR<View>( L, view, LUABIND_METATABLE_STRING("View") );
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * w,h Window:GetWindowSize()
 *****************************************************************************/
INTERN int 
Window_GetWindowSize( lua_State* L ) 
{ 
   try { 

        const WidthHeight<int> wh = GET_WINDOW().GetWindowSize();
        lua_pushnumber( L, wh.w );
        lua_pushnumber( L, wh.h );
        return 2;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool Window:RestoreViewpoint()
 *****************************************************************************/
INTERN int 
Window_RestoreViewpoint( lua_State* L ) 
{ 
   try { 

        lua_pushboolean( L, GET_WINDOW().RestoreViewpoint() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool Window:SaveViewpoint()
 *****************************************************************************/
INTERN int 
Window_SaveViewpoint( lua_State* L ) 
{ 
   try { 

        lua_pushboolean( L, GET_WINDOW().SaveViewpoint() );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

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

#if ! DOXYGEN 

INTERN const struct luaL_reg sMethodTable[] =
{
  // New(),__gc() omitted as Lua cannot instantiate this C++ class.
  { "GetFPS", Window_GetFPS },
  { "GetMainView", Window_GetMainView },
  { "GetWindowSize", Window_GetWindowSize },
  { "RestoreViewpoint", Window_RestoreViewpoint },
  { "SaveViewpoint", Window_SaveViewpoint },
  { NULL, NULL }
};

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

#endif // ! DOXYGEN 

} // namespace bind 

} // namespace lua 
