From ece95a95e95caa6213db0c4f16bd377f6136064b Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sun, 25 Jun 2023 16:16:23 +0800 Subject: [PATCH] Updated docs for improved string_format Edited error messages for a few functions. ConsoleWindow: disallowed negative window position. --- artifacts/scripting/functions.yml | 8 +++++--- artifacts/scripting/sfall function notes.md | 9 +++++---- sfall/ConsoleWindow.cpp | 10 +++++----- sfall/Modules/Karma.cpp | 2 +- sfall/Modules/Scripting/Handlers/Objects.cpp | 4 ++-- sfall/Modules/Scripting/Handlers/Utils.cpp | 15 +++++++-------- sfall/Modules/Scripting/Opcodes.h | 1 - 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/artifacts/scripting/functions.yml b/artifacts/scripting/functions.yml index cb2af0a0..38b9dd25 100644 --- a/artifacts/scripting/functions.yml +++ b/artifacts/scripting/functions.yml @@ -1072,7 +1072,9 @@ items: - name: sprintf detail: string sprintf(string format, any value) - doc: Formats given value using standart syntax of C printf function (google "printf" for format details). However it is limited to formatting only 1 value. Can be used to get character by ASCII code ("%c"). + doc: | + Formats given value using standart syntax of C `printf` function (google "printf" for format details). However, it is limited to formatting only 1 value. + - Can be used to get character by ASCII code ("%c"). opcode: 0x8250 - name: typeof detail: int typeof(any value) @@ -1117,8 +1119,8 @@ - name: string_format detail: string string_format(string format, any val1, any val2, ...) doc: | - Formats given value using standard syntax of C printf function (google "printf" for format details). However it is limited to formatting up to 4 values. - - formatting is only supported for %s and %d, and the format string is limited to 1024 characters + Formats given values using standard syntax of C `printf` function (google "printf" for format details). However, it is limited to formatting up to 7 values. + - The format string is limited to 1024 characters macro: sfall.h - name: string_to_case detail: string sfall_func2("string_to_case", string text, int toCase) diff --git a/artifacts/scripting/sfall function notes.md b/artifacts/scripting/sfall function notes.md index 917a8086..51a4e231 100644 --- a/artifacts/scripting/sfall function notes.md +++ b/artifacts/scripting/sfall function notes.md @@ -339,7 +339,7 @@ FUNCTION REFERENCE ----- ##### `string sprintf(string format, any value)` -- Formats given value using standard syntax of C `printf` function (google "printf" for format details). However it is limited to formatting only 1 value. +- Formats given value using standard syntax of C `printf` function (google "printf" for format details). However, it is limited to formatting only 1 value. - Can be used to get character by ASCII code (`%c`). ----- @@ -930,9 +930,10 @@ sfall_funcX metarule functions ---- #### string_format -`string sfall_func3("string_format", string format, any val1, any val2, ...)` -- Formats given value using standard syntax of C `printf` function (google "printf" for format details). However it is limited to formatting up to 4 values -- Formatting is only supported for `%s` and `%d`, and the format string is limited to 1024 characters +`string sfall_func2("string_format", string format, any val1)` +`string sfall_funcX("string_format", string format, any val1, any val2, ...)` +- Formats given values using standard syntax of C `printf` function (google "printf" for format details). However, it is limited to formatting up to 7 values +- The format string is limited to 1024 characters ---- #### objects_in_radius diff --git a/sfall/ConsoleWindow.cpp b/sfall/ConsoleWindow.cpp index 7ba47bd9..e3312ea1 100644 --- a/sfall/ConsoleWindow.cpp +++ b/sfall/ConsoleWindow.cpp @@ -58,13 +58,13 @@ void ConsoleWindow::loadPosition() { windowData[i] = atoi(windowDataSplit.at(i).c_str()); } int screenWidth = GetSystemMetrics(SM_CXSCREEN), - screenHeight = GetSystemMetrics(SM_CYSCREEN); + screenHeight = GetSystemMetrics(SM_CYSCREEN); int w = min(max(windowData[2], 640), screenWidth), - h = min(max(windowData[3], 480), screenHeight), - x = min(max(windowData[0], -w/2), screenWidth - w/2), - y = min(max(windowData[1], -h/2), screenHeight - h/2); + h = min(max(windowData[3], 480), screenHeight), + x = min(max(windowData[0], 0), screenWidth - w/2), + y = min(max(windowData[1], 0), screenHeight - h/2); - dlog_f("Settings Console Window pos: %d, %d, size: %dx%d. Screen: %dx%d.\n", DL_MAIN, x, y, w, h, screenWidth, screenHeight); + dlog_f("Setting console window position: (%d, %d), size: %dx%d\n", DL_MAIN, x, y, w, h); if (!SetWindowPos(wnd, HWND_TOP, 0, 0, w, h, SWP_NOMOVE)) { dlog_f("Error resizing console window: 0x%x\n", DL_MAIN, GetLastError()); } diff --git a/sfall/Modules/Karma.cpp b/sfall/Modules/Karma.cpp index 8513e10f..8f21fa8f 100644 --- a/sfall/Modules/Karma.cpp +++ b/sfall/Modules/Karma.cpp @@ -43,7 +43,7 @@ bool displayKarmaChanges; static DWORD __stdcall DrawCard() { int reputation = fo::var::game_global_vars[fo::GVAR_PLAYER_REPUTATION]; - for (auto& info : karmaFrms) { + for (const auto& info : karmaFrms) { if (reputation < info.points) { return info.frm; } diff --git a/sfall/Modules/Scripting/Handlers/Objects.cpp b/sfall/Modules/Scripting/Handlers/Objects.cpp index 734a7bba..b725222c 100644 --- a/sfall/Modules/Scripting/Handlers/Objects.cpp +++ b/sfall/Modules/Scripting/Handlers/Objects.cpp @@ -157,7 +157,7 @@ void op_set_script(OpcodeContext& ctx) { long scriptIndex = valArg & ~0xF0000000; if (scriptIndex == 0 || valArg > 0x8FFFFFFF) { // negative values are not allowed - ctx.printOpcodeError("%s() - the script index number is incorrect.", ctx.getOpcodeName()); + ctx.printOpcodeError("%s() - invalid script index number.", ctx.getOpcodeName()); return; } scriptIndex--; @@ -430,7 +430,7 @@ void mf_item_make_explosive(OpcodeContext& ctx) { if (pid > 0 && pidActive > 0) { Explosions::AddToExplosives(pid, pidActive, min, max); } else { - ctx.printOpcodeError("%s() - invalid PID number, must be greater than 0.", ctx.getMetaruleName()); + ctx.printOpcodeError("%s() - invalid PID number.", ctx.getMetaruleName()); ctx.setReturn(-1); } } diff --git a/sfall/Modules/Scripting/Handlers/Utils.cpp b/sfall/Modules/Scripting/Handlers/Utils.cpp index bf8e6108..d1d5ed9b 100644 --- a/sfall/Modules/Scripting/Handlers/Utils.cpp +++ b/sfall/Modules/Scripting/Handlers/Utils.cpp @@ -232,8 +232,7 @@ static const char* sprintf_lite(OpcodeContext& ctx, const char* opcodeName) { } else { if (c == '%') { conversion = false; // escaped % sign, just skip - } - else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { + } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { // ignore size prefixes if (c == 'h' || c == 'l' || c == 'j' || c == 'z' || c == 't' || c == 'w' || c == 'L' || c == 'I') continue; // Type specifier, perform conversion. @@ -242,18 +241,18 @@ static const char* sprintf_lite(OpcodeContext& ctx, const char* opcodeName) { } const auto& arg = ctx.arg(valIdx < numArgs ? valIdx : numArgs - 1); if (c == 'S' || c == 'Z') { - c = 's'; // don't allow wide-strings. + c = 's'; // don't allow wide strings } - if (c == 's' && !arg.isString() || // don't allow to treat non-string values as string pointers - c == 'n') // don't allow "n" specifier + if (c == 's' && !arg.isString() || // don't allow treating non-string values as string pointers + c == 'n') // don't allow "n" specifier { c = 'd'; } newFmt[j++] = c; newFmt[j] = '\0'; int partLen = arg.isFloat() - ? _snprintf(outBuf, bufCount, newFmt, arg.floatValue()) - : _snprintf(outBuf, bufCount, newFmt, arg.rawValue()); + ? _snprintf(outBuf, bufCount, newFmt, arg.floatValue()) + : _snprintf(outBuf, bufCount, newFmt, arg.rawValue()); outBuf += partLen; bufCount -= partLen; conversion = false; @@ -278,7 +277,7 @@ static const char* sprintf_lite(OpcodeContext& ctx, const char* opcodeName) { void op_sprintf(OpcodeContext& ctx) { ctx.setReturn( - sprintf_lite(ctx, "op_sprintf") + sprintf_lite(ctx, ctx.getOpcodeName()) ); } diff --git a/sfall/Modules/Scripting/Opcodes.h b/sfall/Modules/Scripting/Opcodes.h index 10547873..3f3781b7 100644 --- a/sfall/Modules/Scripting/Opcodes.h +++ b/sfall/Modules/Scripting/Opcodes.h @@ -32,4 +32,3 @@ public: } } -