mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Added "tolower", "toupper" script functions
This commit is contained in:
@@ -281,6 +281,8 @@
|
|||||||
#define string_format(format, a1, a2) sfall_func3("string_format", format, a1, a2)
|
#define string_format(format, a1, a2) sfall_func3("string_format", format, a1, a2)
|
||||||
#define tile_by_position(x, y) sfall_func2("tile_by_position", x, y)
|
#define tile_by_position(x, y) sfall_func2("tile_by_position", x, y)
|
||||||
#define tile_refresh_display sfall_func0("tile_refresh_display")
|
#define tile_refresh_display sfall_func0("tile_refresh_display")
|
||||||
|
#define tolower(text) sfall_func1("tolower", text)
|
||||||
|
#define toupper(text) sfall_func1("toupper", text)
|
||||||
#define unjam_lock(obj) sfall_func1("unjam_lock", obj)
|
#define unjam_lock(obj) sfall_func1("unjam_lock", obj)
|
||||||
#define unset_unique_id(obj) sfall_func2("set_unique_id", obj, -1)
|
#define unset_unique_id(obj) sfall_func2("set_unique_id", obj, -1)
|
||||||
#define unwield_slot(critter, slot) sfall_func2("unwield_slot", critter, slot)
|
#define unwield_slot(critter, slot) sfall_func2("unwield_slot", critter, slot)
|
||||||
|
|||||||
@@ -603,6 +603,14 @@ optional arguments:
|
|||||||
- returns the tile number at the x, y position relative to the top-left corner of the screen
|
- returns the tile number at the x, y position relative to the top-left corner of the screen
|
||||||
- if the position is outside of the range of tiles, it will return -1
|
- if the position is outside of the range of tiles, it will return -1
|
||||||
|
|
||||||
|
> string sfall_func1("tolower", string text)
|
||||||
|
- converts all uppercase letters in the given string to lowercase
|
||||||
|
- returns -1 on argument error
|
||||||
|
|
||||||
|
> string sfall_func1("toupper", string text)
|
||||||
|
- converts all lowercase letters in the given string to uppercase
|
||||||
|
- returns -1 on argument error
|
||||||
|
|
||||||
------------------------
|
------------------------
|
||||||
------ MORE INFO -------
|
------ MORE INFO -------
|
||||||
------------------------
|
------------------------
|
||||||
|
|||||||
@@ -432,6 +432,8 @@ static const SfallOpcodeMetadata opcodeMetaArray[] = {
|
|||||||
{sf_set_window_flag, "set_window_flag", {DATATYPE_MASK_INT | DATATYPE_MASK_STR, DATATYPE_MASK_INT, DATATYPE_MASK_INT}},
|
{sf_set_window_flag, "set_window_flag", {DATATYPE_MASK_INT | DATATYPE_MASK_STR, DATATYPE_MASK_INT, DATATYPE_MASK_INT}},
|
||||||
{sf_show_window, "show_window", {DATATYPE_MASK_STR}},
|
{sf_show_window, "show_window", {DATATYPE_MASK_STR}},
|
||||||
{sf_tile_by_position, "tile_by_position", {DATATYPE_MASK_INT, DATATYPE_MASK_INT}},
|
{sf_tile_by_position, "tile_by_position", {DATATYPE_MASK_INT, DATATYPE_MASK_INT}},
|
||||||
|
{sf_tolower, "tolower", {DATATYPE_MASK_STR}},
|
||||||
|
{sf_toupper, "toupper", {DATATYPE_MASK_STR}},
|
||||||
{sf_unjam_lock, "unjam_lock", {DATATYPE_MASK_VALID_OBJ}},
|
{sf_unjam_lock, "unjam_lock", {DATATYPE_MASK_VALID_OBJ}},
|
||||||
{sf_unwield_slot, "unwield_slot", {DATATYPE_MASK_VALID_OBJ, DATATYPE_MASK_INT}},
|
{sf_unwield_slot, "unwield_slot", {DATATYPE_MASK_VALID_OBJ, DATATYPE_MASK_INT}},
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|||||||
@@ -173,6 +173,8 @@ static const SfallMetarule metaruleArray[] = {
|
|||||||
{"string_format", sf_string_format, 2, 5},
|
{"string_format", sf_string_format, 2, 5},
|
||||||
{"tile_by_position", sf_tile_by_position, 2, 2},
|
{"tile_by_position", sf_tile_by_position, 2, 2},
|
||||||
{"tile_refresh_display", sf_tile_refresh_display, 0, 0},
|
{"tile_refresh_display", sf_tile_refresh_display, 0, 0},
|
||||||
|
{"tolower", sf_tolower, 1, 1},
|
||||||
|
{"toupper", sf_toupper, 1, 1},
|
||||||
{"unjam_lock", sf_unjam_lock, 1, 1},
|
{"unjam_lock", sf_unjam_lock, 1, 1},
|
||||||
{"unwield_slot", sf_unwield_slot, 2, 2},
|
{"unwield_slot", sf_unwield_slot, 2, 2},
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|||||||
@@ -998,3 +998,28 @@ static void sf_get_text_width() {
|
|||||||
opHandler.setReturn(0);
|
opHandler.setReturn(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char* _stdcall cstrdup(const char* str) {
|
||||||
|
size_t len = strlen(str);
|
||||||
|
const size_t bufMaxLen = GlblTextBufferSize() - 1;
|
||||||
|
if (len > bufMaxLen) len = bufMaxLen;
|
||||||
|
|
||||||
|
if (len) memcpy(gTextBuffer, str, len);
|
||||||
|
gTextBuffer[len] = '\0';
|
||||||
|
|
||||||
|
return gTextBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sf_tolower() {
|
||||||
|
std::string str = std::string(opHandler.arg(0).strValue());
|
||||||
|
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
||||||
|
|
||||||
|
opHandler.setReturn(cstrdup(str.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sf_toupper() {
|
||||||
|
std::string str = std::string(opHandler.arg(0).strValue());
|
||||||
|
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
|
||||||
|
|
||||||
|
opHandler.setReturn(cstrdup(str.c_str()));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user