polserver/pol-core/support/scripts/basic.em

114 lines
4.1 KiB
Text
Raw Permalink Normal View History

// format-off
const TRIM_LEFT := 0x1; // Trim whitespace from Left of string.
const TRIM_RIGHT := 0x2; // Trim whitespace from Right of string.
const TRIM_BOTH := 0x3; // Trim whitespace from Left and Right of string.
// TypeOfInt() constants
const OT_UNKNOWN := 0;
const OT_UNINIT := 1;
const OT_STRING := 2;
const OT_LONG := 3;
const OT_DOUBLE := 4;
const OT_ARRAY := 5;
const OT_APPLICPTR := 6;
const OT_APPLICOBJ := 7;
const OT_ERROR := 8;
const OT_DICTIONARY := 9;
const OT_STRUCT := 10;
const OT_PACKET := 11;
const OT_BINARYFILE := 12;
const OT_XMLFILE := 13;
const OT_XMLNODE := 14;
const OT_XMLATTRIBUTES := 15;
const OT_POLCOREREF := 16;
const OT_ACCOUNTREF := 17;
const OT_CONFIGFILEREF := 18;
const OT_CONFIGELEMREF := 19;
const OT_DATAFILEREF := 20;
const OT_DATAELEMREF := 21;
const OT_GUILDREF := 22;
const OT_PARTYREF := 23;
const OT_BOUNDINGBOX := 24;
const OT_DEBUGCONTEXT := 25;
const OT_SCRIPTEXREF := 26;
const OT_PACKAGE := 27;
const OT_MENUREF := 28;
const OT_MOBILEREF := 29;
const OT_OFFLINEMOBILEREF := 30;
const OT_ITEMREF := 31;
const OT_BOATREF := 32;
const OT_MULTIREF := 33;
const OT_CLIENTREF := 34;
const OT_SQLCONN := 35; // Only applicable if SQL is active and compiled.
const OT_SQLRESULT := 36;
const OT_SQLROW := 37;
const OT_BOOLEAN := 38;
const OT_FUNCOBJECT := 39;
Testsuite reorganization, new feature to call exported functions (#237) * restructured pol testscripts pkg based (dedicated pkgroot) runs per pkg: setup.ecl if exists all scripts starting with "test" cleanup.ecl if exists return 1 for success everything else is an error * Scripts can now be loaded and exported functions called adapted testscripts to use this feature critical script handling missing * added support for used in critical scripts * use weakptr instead of pid moved keep_alive flag to uoexecutor * Function and nethod accept now a argument list * added docs * missing docs * faster shutdown time * fixed typo * fixed weird cornercase * shorter test functions names, the length is limited, renamed loadexported test script to have a dedicated testscript * generate tiledata/multi for small boat added generate scripts for generation.. adapted testdata set * boat tests * extended scripttests scheduler will now always know about the loaded script secured scheduler api * cleanuo scripts for boat and npc * shorter function for error return fixed cleanup: npcs have gravestones, chars was one off and scripted create of a char made it permanent logged in (until next restart), which also means that it cannot be deleted * bypass windows specific ecompile.cfg logic * fix for parallel execution * on windows its called .exe .. * use target binary directly, so cmake can replace it with the actual path use absolute path to testsuite disabled temporary the copy of ecompile * configure ecompile.cfg to add absolute path * early sleepms calls can lead to endless waiting * Code coverage (#260) * play with coverage reports * fix yml * use 0 as default for gcov cmake var * fixed used cov version, hopefully fixed now cmake * demangle function names * removed debug msg * added a few polcore tests (basically just for coverage) first set executor to noncritical before blocking * added https://coveralls.io/github/polserver/polserver * added a stackable item added a few backpack insert tests do coverage build only on push events not also for PR merge builds * added storage tests.. docs need fixes, the Imps are not working at all * fixed storage test to really move items * added a house corrected static/dynamic flag created a few house tests * updated yml file to new github api * corrected coverage discord job name * always put to runlist even if not necessary * extended aos prop tests * equip/unequip aos mod * extra ci step for shard test fixtures and activated verbose shard test * use extra ci step for all build configs, sorted testscripts for execution * fixed sorting * added param to syslog to not print the context (cleaner testscript visualization) * added build targets for tests * sleep api cleanup * more aos property tests * build for coveralls also on pullrequest * readded debug state reset on schedule * updated checkout ci action * updated checkout in all ci runs
2020-12-16 18:56:10 +01:00
const OT_EXPORTEDSCRIPT := 40;
const OT_STORAGEAREA := 41;
const OT_CLASSINSTANCEREF := 42;
Add support for regular expressions (#818) * implementation * tests * maybe fix windows compilation? * undo change of match_flag_type * switch to boost regex * move flags to BRegExp object * fix tests due to cmake 4 update * update grammar * update prettifier * move flag parsing to BRegExp ctor * add AST nodes, update instr generation and execution * copy tests but use regular expression literals * fix grammar for handling division correctly * modify return values a bit, update tests - string.match: make groups hold structs of matched, offset - string.match: add offset - string.replace: use a groups array like string.match vs individual arguments * bundle of changes - standardize error messages - add more tests for coverage - move BRegExp creation to static method: previous implementation had ctor throwing, which was no good inside executor since it didn't have a try/catch * more tests; add OT_REGEXP to basic.em * move string regex stuff to bregexp and support regex/wregex via std::visit * maybe fix compilation errors? * add unicode escape sequence handling * really maybe fix compilation error? * fix compiler warnings * refactor a bit to remove duplicate code * address discord comments - just return wstring, no need for vector<wchar_t> method * Add string.split by string and regexp * Use Max_Split instead of Limit This makes it match basic::SplitWords * add support for empty string delim in SplitWords * remove duplicate code across string.split and mf_SplitWords * Squashed commit of the following: commit b3148e069f4c4bad041b36144d312f375c028a6c Author: turleypol <turley@polserver.com> Date: Sat Sep 27 17:02:22 2025 +0200 memorylocation of input string is not allowed to changed, switched back to uniqueptr commit 5a4d1c8fcb2d8239ba0b693644dd20d9a5a167bb Author: turleypol <turley@polserver.com> Date: Sat Sep 27 10:18:01 2025 +0200 no need to use ptr for input commit 90fa0edc66034db77a43222612b4981bf09081a5 Author: turleypol <turley@polserver.com> Date: Sat Sep 27 09:56:29 2025 +0200 fixed typo commit bed4ff3ac9de88fb9e91350125339c8ab04c2da3 Author: turleypol <turley@polserver.com> Date: Sat Sep 27 09:47:36 2025 +0200 make Callback for BContinuation move only * use uninit when group isn't matched * fix multiline flag handling; add test * add docs and doc example tests * some cleanup * address review comments - allow move assignment * add core-changes
2025-11-17 18:02:45 +01:00
const OT_REGEXP := 43;
// format-on
// returns the one-based index of Search within Str after position Start
Find( Str, Search, Start );
// len(): For strings, returns string length
// For arrays, returns number of elements.
Len( Str_or_array );
// upper(): Convert whole string to upper-case
// lower(): Convert whole string to lower-case
Upper( Str );
Lower( Str );
// Various Conversion Functions
//
CInt( expr ); // Convert to integer
CDbl( expr ); // Convert to double
CStr( expr ); // Convert to string
CAsc( str ); // Convert first character to Ascii value (0-255)
CChr( number ); // Convert Ascii value to character (type: string)
CAscZ( str, nullterm := 0 ); // Convert string to array of Ascii values (0-255)
CChrZ( intarray, break_at_first_null := 0 ); // Convert array of Ascii values to a string
Bin( number ); // Convert 25 to 11001
Hex( number ); // Convert to 0x[hex val] - 0x0 to 0xFFFFFFFF
// Compare(): Compares 2 strings and returns based results.
// 1 = Match
// 0 = Not a match
Compare( str1, str2, pos1_start := 0, pos1_end := 0, pos2_start := 0, pos2_end := 0 );
// SplitWords: returns an array of words contained in str, based
// on optional delimiter. Default delim is blank space.
// on optional max_split. Default -1 for unlimited.
SplitWords( str, delimiter := " ", max_split := -1 );
// SubStr(): Returns substring beginning at start until length.
SubStr( str, start, length );
// Trim(): Returns string with whitespace cleared based on Type and Character to trim.
// set: Character set to trim
// type: 1 = Trim Leading, 2 = Trim Trailing, 3 = Trim Both.
Trim( str, type := TRIM_BOTH, to_trim := " " );
// StrReplace(): Replace instance of to_replace with replace_with in str.
StrReplace( str, to_replace, replace_with );
// SubStrReplace(): Replace portion of string using replace_with, beginning at start for length.
SubStrReplace( str, replace_with, start, length := 0 );
// Pack and Unpack: convert an object to a storable string form
// Pack( 5 ) returns "i5"
// Unpack( "i5" ) returns 5
// strings, integers, reals, and arrays and dictionaries of these can be packed.
Pack( expr );
Unpack( str );
TypeOf( expr ); // returns "Integer", "Real" etc
SizeOf( expr ); // returns estimate of memory used
TypeOfInt( expr ); // returns Integer representation of TypeOf string
PackJSON( expr, pretty := 0 );
2018-01-05 20:40:14 +01:00
UnpackJSON( jsonStr );
Boolean( number ); // returns boolean instance
2018-07-20 00:28:01 +10:00
EncodeBase64( str );
DecodeBase64( str );
Add support for regular expressions (#818) * implementation * tests * maybe fix windows compilation? * undo change of match_flag_type * switch to boost regex * move flags to BRegExp object * fix tests due to cmake 4 update * update grammar * update prettifier * move flag parsing to BRegExp ctor * add AST nodes, update instr generation and execution * copy tests but use regular expression literals * fix grammar for handling division correctly * modify return values a bit, update tests - string.match: make groups hold structs of matched, offset - string.match: add offset - string.replace: use a groups array like string.match vs individual arguments * bundle of changes - standardize error messages - add more tests for coverage - move BRegExp creation to static method: previous implementation had ctor throwing, which was no good inside executor since it didn't have a try/catch * more tests; add OT_REGEXP to basic.em * move string regex stuff to bregexp and support regex/wregex via std::visit * maybe fix compilation errors? * add unicode escape sequence handling * really maybe fix compilation error? * fix compiler warnings * refactor a bit to remove duplicate code * address discord comments - just return wstring, no need for vector<wchar_t> method * Add string.split by string and regexp * Use Max_Split instead of Limit This makes it match basic::SplitWords * add support for empty string delim in SplitWords * remove duplicate code across string.split and mf_SplitWords * Squashed commit of the following: commit b3148e069f4c4bad041b36144d312f375c028a6c Author: turleypol <turley@polserver.com> Date: Sat Sep 27 17:02:22 2025 +0200 memorylocation of input string is not allowed to changed, switched back to uniqueptr commit 5a4d1c8fcb2d8239ba0b693644dd20d9a5a167bb Author: turleypol <turley@polserver.com> Date: Sat Sep 27 10:18:01 2025 +0200 no need to use ptr for input commit 90fa0edc66034db77a43222612b4981bf09081a5 Author: turleypol <turley@polserver.com> Date: Sat Sep 27 09:56:29 2025 +0200 fixed typo commit bed4ff3ac9de88fb9e91350125339c8ab04c2da3 Author: turleypol <turley@polserver.com> Date: Sat Sep 27 09:47:36 2025 +0200 make Callback for BContinuation move only * use uninit when group isn't matched * fix multiline flag handling; add test * add docs and doc example tests * some cleanup * address review comments - allow move assignment * add core-changes
2025-11-17 18:02:45 +01:00
RegExp( pattern, flags := "" );