From 6ccd48f7191f8e32a102723dfb31c15bd173f1e6 Mon Sep 17 00:00:00 2001 From: false_genesis Date: Sun, 17 Feb 2008 21:32:21 +0000 Subject: [PATCH] * fixed scripted uint64 appending to bytebuffer, patch by bLuma, thx! --- src/Client/DefScript/DefScriptBBFunctions.cpp | 15 ++++++++------- src/Client/DefScript/DefScriptTools.cpp | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Client/DefScript/DefScriptBBFunctions.cpp b/src/Client/DefScript/DefScriptBBFunctions.cpp index 46d5cf4..7e534c8 100644 --- a/src/Client/DefScript/DefScriptBBFunctions.cpp +++ b/src/Client/DefScript/DefScriptBBFunctions.cpp @@ -11,7 +11,8 @@ using namespace DefScriptTools; // Helper macros for insert/extract various datatypes that need type casting #define BB_CAN_READ(bytebuffer, _ty) ((*(bytebuffer)).size() - (*(bytebuffer)).rpos() >= sizeof(_ty)) -#define BB_MACRO_INSERT(bytebuffer, _sty, _ty) if( (_sty)==(#_ty) ) { *(bytebuffer) << (_ty)toNumber(Set.defaultarg); return true; } +#define BB_MACRO_INSERT_I(bytebuffer, _sty, _ty) if( (_sty)==(#_ty) ) { *(bytebuffer) << (_ty)toUint64(Set.defaultarg); return true; } +#define BB_MACRO_INSERT_F(bytebuffer, _sty, _ty) if( (_sty)==(#_ty) ) { *(bytebuffer) << (_ty)toNumber(Set.defaultarg); return true; } #define BB_MACRO_EXTRACT_I(bytebuffer, _sty, _ty) if( (_sty)==(#_ty) && BB_CAN_READ(bytebuffer,_ty) ) {_ty _var; *(bytebuffer) >> _var; return DefScriptTools::toString((uint64)_var); } #define BB_MACRO_EXTRACT_F(bytebuffer, _sty, _ty) if( (_sty)==(#_ty) && BB_CAN_READ(bytebuffer,_ty) ) {_ty _var; *(bytebuffer) >> _var; return DefScriptTools::toString((ldbl)_var); } @@ -56,12 +57,12 @@ DefReturnResult DefScriptPackage::func_bbappend(CmdSet& Set) return true; } - BB_MACRO_INSERT(bb, dtype, uint8); - BB_MACRO_INSERT(bb, dtype, uint16); - BB_MACRO_INSERT(bb, dtype, uint32); - BB_MACRO_INSERT(bb, dtype, uint64); - BB_MACRO_INSERT(bb, dtype, float); - BB_MACRO_INSERT(bb, dtype, double); + BB_MACRO_INSERT_I(bb, dtype, uint8); + BB_MACRO_INSERT_I(bb, dtype, uint16); + BB_MACRO_INSERT_I(bb, dtype, uint32); + BB_MACRO_INSERT_I(bb, dtype, uint64); + BB_MACRO_INSERT_F(bb, dtype, float); + BB_MACRO_INSERT_F(bb, dtype, double); return false; } diff --git a/src/Client/DefScript/DefScriptTools.cpp b/src/Client/DefScript/DefScriptTools.cpp index d2bb97f..258cfb6 100644 --- a/src/Client/DefScript/DefScriptTools.cpp +++ b/src/Client/DefScript/DefScriptTools.cpp @@ -110,7 +110,7 @@ bool DefScriptTools::isTrue(std::string s) uint64 DefScriptTools::toUint64(std::string str) { bool negative=false; - uint64 num; + uint64 num = 0; if(str.empty()) return 0; if(str[0]=='-') @@ -157,4 +157,4 @@ inline long double DefScriptTools::Round(long double z,unsigned int n) { static long double v[] = { 1, 10, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16 }; return floor(z * v[n] + 0.5) / v[n]; -} \ No newline at end of file +}