From 8db394c85dfef19f15a7b78a2b8e611c53176fc4 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 29 Jan 2007 22:34:53 +0000 Subject: [PATCH] Added VFormat() native --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40417 --- core/smn_string.cpp | 53 ++++++++++++++++++++++++++++++++++++++++ core/vm/sp_vm_engine.cpp | 2 -- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/core/smn_string.cpp b/core/smn_string.cpp index 162ea4bd..0d746722 100644 --- a/core/smn_string.cpp +++ b/core/smn_string.cpp @@ -170,6 +170,58 @@ static cell_t sm_format(IPluginContext *pCtx, const cell_t *params) return static_cast(res); } +static cell_t sm_vformat(IPluginContext *pContext, const cell_t *params) +{ + int vargPos = static_cast(params[4]); + + /* Get the parent parameter array */ + sp_context_t *ctx = pContext->GetContext(); + cell_t *local_params = (cell_t *)(ctx->memory + ctx->frm + (2 * sizeof(cell_t))); + + cell_t max = local_params[0]; + if (vargPos > (int)max + 1) + { + return pContext->ThrowNativeError("Argument index is invalid: %d", vargPos); + } + + cell_t addr_start = params[1]; + cell_t addr_end = addr_start + params[2]; + bool copy = false; + for (int i=vargPos; i<=max; i++) + { + /* Does this clip bounds? */ + if ((local_params[i] >= addr_start) + && (local_params[i] <= addr_end)) + { + copy = true; + break; + } + } + + /* Get destination info */ + char *format, *destination; + size_t maxlen = static_cast(params[2]); + + if (copy) + { + destination = g_formatbuf; + } else { + pContext->LocalToString(params[1], &destination); + } + + pContext->LocalToString(params[3], &format); + + size_t total = atcprintf(destination, maxlen, format, pContext, local_params, &vargPos); + + /* Perform copy-on-write if we need to */ + if (copy) + { + pContext->StringToLocal(params[1], maxlen, g_formatbuf); + } + + return total; +} + REGISTER_NATIVES(basicstrings) { {"strlen", sm_strlen}, @@ -182,5 +234,6 @@ REGISTER_NATIVES(basicstrings) {"FloatToString", sm_floattostr}, {"Format", sm_format}, {"FormatEx", sm_formatex}, + {"VFormat", sm_vformat}, {NULL, NULL}, }; diff --git a/core/vm/sp_vm_engine.cpp b/core/vm/sp_vm_engine.cpp index d59b70b3..49d6fa25 100644 --- a/core/vm/sp_vm_engine.cpp +++ b/core/vm/sp_vm_engine.cpp @@ -74,8 +74,6 @@ SourcePawnEngine::SourcePawnEngine() SourcePawnEngine::~SourcePawnEngine() { - assert(m_CallStack == NULL); - TracedCall *pTemp; while (m_FreedCalls) {