/*****************************************************************************
 * $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"
#include "base/conf_bin.hh"
using namespace base;
#include "glue/module.hh"
#include "glue/conf_bin_ext.hh"
using namespace glue;
#include "lua_bind/module.hh"
#include "lua_bind/bind.hh"

namespace lua {


namespace bind {

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

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

/*****************************************************************************
 * true,number or false,nil ConfBin:ReadInt( key )
 *****************************************************************************/
INTERN int 
ConfBin_ReadInt( lua_State* L ) 
{ 
   try { 

        const string key = POP_STRING( L );
        int val = 0;
        const bool res = glue::GetConfBin().Read( key, val );
        if ( res )
        {
            lua_pushboolean( L, true );
            lua_pushnumber( L, val );
        }
        else
        {
            lua_pushboolean( L, false );
            lua_pushnil( L );
        }
        return 2;  // stack items to return
    
   } CATCH_LUA_EXCEPTION 
   return 0; 
} 

/*****************************************************************************
 * bool ConfBin:WriteInt( key, val )
 *****************************************************************************/
INTERN int 
ConfBin_WriteInt( lua_State* L ) 
{ 
   try { 

        const int    val = POP_INT( L );
        const string key = POP_STRING( L );
        const bool res = glue::GetConfBin().Write( key, val );
        lua_pushboolean( L, res );
        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.
  { "ReadInt", ConfBin_ReadInt },
  { "WriteInt", ConfBin_WriteInt },
  { NULL, NULL }
};

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

#endif // ! DOXYGEN 

} // namespace bind 

} // namespace lua 
