Ejemplo n.º 1
0
/**	@name	hexDecode
	@text	If a string is provided, decodes it as a hex encoded string.  Otherwise, decodes the current data stored in this object as a hex encoded sequence of bytes.

	@opt	MOAIDataBuffer self
	@opt	string data				The string data to decode.  You must either provide either a MOAIDataBuffer (via a :hexDecode type call) or string data (via a .hexDecode type call), but not both.
	@out	string output			If passed a string, returns either a string or nil depending on whether it could be decoded.  Otherwise the decoding occurs inline on the existing data buffer in this object, and nil is returned.
*/
int MOAIDataBuffer::_hexDecode ( lua_State* L ) {
	MOAILuaState state ( L );
	
	if ( state.IsType ( 1, LUA_TSTRING )) {
		return state.HexDecode ( 1 ) ? 1 : 0;
	}
	
	MOAIDataBuffer* self = state.GetLuaObject < MOAIDataBuffer >( 1, true );
	if ( self ) {
		if ( state.IsType ( 2, LUA_TSTRING )) {
			size_t len;
			cc8* str = lua_tolstring ( state, 2, &len );
			self->Load (( void* )str, len );
		}
		self->HexDecode ();
	}
	return 0;
}