mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Updated docs for improved string_format
Edited error messages for a few functions. ConsoleWindow: disallowed negative window position.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,4 +32,3 @@ public:
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user