-- $LastChangedDate: 2011-03-17 19:59:52 -0400 (Thu, 17 Mar 2011) $
-- Macros written in Lua to expand C++ code for bindings between C++/Lua.
-- Avoid lua_/LUA_ which is reserved by Lua.

bindTable = {

class = "lib",
typesig = nil,
luaCanInstantiate = false,

headers =
[[
#include "base/module.hh"
#include "base/bits.hh"
#include "base/misc.hh"
using namespace base;
]],

func_SignedHexNumber2String = {
    comments = "string lib:SignedHexNumber2String( signedHexNumber, {minWidth,noShowBase,padZeros,showPlus} )",
    code = [[
        eNumberFormat format = eNumberFormat(0);
        uint minWidth = 0;

        BEGIN_OPTIONAL_TABLE_MEMBER
            minWidth = GET_MEMBER_AS_NUMBER( L, "minWidth", OPTIONAL );
        END_OPTIONAL_TABLE_MEMBER

        BEGIN_OPTIONAL_TABLE_MEMBER
            if ( GET_MEMBER_AS_BOOL( L, "noShowBase", OPTIONAL ) )
                format = SetBit<eNumberFormat>( format, eNumberFormat_NO_SHOW_BASE );
        END_OPTIONAL_TABLE_MEMBER

        BEGIN_OPTIONAL_TABLE_MEMBER
            if ( GET_MEMBER_AS_BOOL( L, "padZeros", OPTIONAL ) )
                format = SetBit<eNumberFormat>( format, eNumberFormat_PAD_ZEROS );
        END_OPTIONAL_TABLE_MEMBER

        BEGIN_OPTIONAL_TABLE_MEMBER
            if ( GET_MEMBER_AS_BOOL( L, "showPlus", OPTIONAL ) )
                format = SetBit<eNumberFormat>( format, eNumberFormat_SHOW_PLUS );
        END_OPTIONAL_TABLE_MEMBER

        // Pop the passed table arg.
        lua_pop( L, 1 );

        // Pop hex number.
        const long signedHexValue = long(POP_FP(L));

        const string hexStr = SignedHexNumber2String( signedHexValue, minWidth, format );
        lua_pushstring( L, hexStr.c_str() );
        return 1;  // stack items to return
    ]]
},

}
