summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2014-02-08 02:19:41 +0100
committerHaru <haru@dotalux.com>2014-02-08 02:33:49 +0100
commit1cf7c1ec251d6899707b0eced3bc75da2e212557 (patch)
tree54008176b1b0fca8affc1e01b1fac7b98e67df95 /doc
parente7853fa6ed991fdd7bcb4b2c842761742ae3c912 (diff)
downloadhercules-1cf7c1ec251d6899707b0eced3bc75da2e212557.tar.gz
hercules-1cf7c1ec251d6899707b0eced3bc75da2e212557.tar.bz2
hercules-1cf7c1ec251d6899707b0eced3bc75da2e212557.tar.xz
hercules-1cf7c1ec251d6899707b0eced3bc75da2e212557.zip
Improvements on the script commands sscanf, axtoi. Added strtol.
- Added script command strtol (conforming to the ISO C90 function) - Modified script command axtoi to internally use strtol instead of an unnecessary own implementation. - Fixed sscanf behavior to conform to the C specifications in case the input string is empty. It now correctly returns -1, or 0 if the format string is also empty. Fixes bugreport:8009, thanks to AnnieRuru - http://hercules.ws/board/tracker/issue-8009-sscanf-should-return-1-if-the-string-field-is-an-empty-string/ Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/script_commands.txt25
1 files changed, 18 insertions, 7 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index c0b848663..aa8698418 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -7359,20 +7359,31 @@ setitemscript 2637,"";
---------------------------------------
-*atoi ("<string>")
-*axtoi ("<string>")
+*atoi("<string>")
+*axtoi("<string>")
+*strtol("string", base)
These commands are used to convert strings to numbers. 'atoi' will
interpret given string as a decimal number (base 10), while 'axtoi'
-interprets strings as hexadecimal numbers (base 16).
+interprets strings as hexadecimal numbers (base 16). 'strtol' lets
+the user specify a base (valid range is between 2 and 36 inclusive,
+or the special value0, which means auto-detection).
-Hexadecimal number set: {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
+The atoi and strtol functions conform to the C functions with the same
+names, and axtoi is the same as strtol, with a base of 16. Results are
+clamped to signed 32 bit int range (INT_MIN ~ INT_MAX)
Example:
-set @var, atoi("11"); // Sets @var to 11
-set @var, axtoi("FF"); // Sets @var to 255
-mes axtoi("11"); // Displays 17 (1 = 1, 10 = 16)
+.@var = atoi("11"); // Sets .@var to 11
+.@var = axtoi("FF"); // Sets .@var to 255
+mes axtoi("11"); // Displays 17 (1 = 1, 10 = 16)
+.@var = strtol("11", 10); // Sets .@var to 11 (11 base 10)
+.@var = strtol("11", 16); // Sets .@var to 17 (11 base 16)
+.@var = strtol("11", 0); // Sets .@var to 11 (11 base 10, auto-detected)
+.@var = strtol("0x11", 0); // Sets .@var to 17 (11 base 16, auto-detected because of the "0x" prefix)
+.@var = strtol("011", 0); // Sets .@var to 9 (11 base 8, auto-detected because of the "0" prefix)
+.@var = strtol("11", 2); // Sets .@var to 3 (binary 11)
---------------------------------------