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

namespace lua {


namespace bind {

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

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

/*****************************************************************************
 * num math:AXIS_INVALID()
 * AXIS_INVALID is defined as ~0 in C++ which varies by CPU,
 * so Lua should get the right value from this.
 *****************************************************************************/
INTERN int 
Math_AXIS_INVALID( lua_State* L ) 
{ 
   try { 

        lua_pushnumber( L, AXIS_INVALID );  // let C++ compiler promote it as usual
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool math:IF_Z_FACING( z )
 * Returns true if the eye coordinate Z is facing the viewpoint.
 *****************************************************************************/
INTERN int 
Math_IF_Z_FACING( lua_State* L ) 
{ 
   try { 

        const fp z = POP_FP( L );
        lua_pushboolean( L, IF_Z_FACING( z ) );
        return 1;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * int math:TruncInt( f ) / truncate Lua number to integer
 *****************************************************************************/
INTERN int 
Math_TruncInt( lua_State* L ) 
{ 
   try { 

        lua_pushnumber( L, long( POP_FP( L ) ) );
        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.
  { "AXIS_INVALID", Math_AXIS_INVALID },
  { "IF_Z_FACING", Math_IF_Z_FACING },
  { "TruncInt", Math_TruncInt },
  { NULL, NULL }
};

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

#endif // ! DOXYGEN 

} // namespace bind 

} // namespace lua 
