diff --git a/libs/ruamoko/rua_string.c b/libs/ruamoko/rua_string.c index fcd78c1cc..c96f44e57 100644 --- a/libs/ruamoko/rua_string.c +++ b/libs/ruamoko/rua_string.c @@ -134,6 +134,18 @@ bi_str_str (progs_t *pr) R_STRING (pr) = res - pr->pr_strings; } +static void +bi_str_char (progs_t *pr) +{ + const char *str = P_GSTRING (pr, 0); + int ind = P_INT (pr, 1); + + if (ind < 0) { + PR_RunError (pr, "negative index to str_char"); + } + R_INT (pr) = str[ind]; +} + static builtin_t builtins[] = { {"str_new", bi_str_new, -1}, {"str_free", bi_str_free, -1}, @@ -143,6 +155,7 @@ static builtin_t builtins[] = { {"str_mid|*i", bi_str_mid, -1}, {"str_mid|*ii", bi_str_mid, -1}, {"str_str", bi_str_str, -1}, + {"str_char", bi_str_char, -1}, {0} }; diff --git a/ruamoko/include/string.h b/ruamoko/include/string.h index d41e94ef8..3951c94c5 100644 --- a/ruamoko/include/string.h +++ b/ruamoko/include/string.h @@ -20,5 +20,6 @@ @extern @overload string str_mid (string str, int start); @extern @overload string str_mid (string str, int start, int len); @extern string str_str (string haystack, string needle); +@extern int str_char (string str, int ind); #endif//__ruamoko_string_h diff --git a/ruamoko/lib/string.r b/ruamoko/lib/string.r index c6c239fa6..58f64911a 100644 --- a/ruamoko/lib/string.r +++ b/ruamoko/lib/string.r @@ -19,3 +19,4 @@ string (string str) str_clear = #0; string (string str, int start) str_mid = #0; string (string str, int start, int len) str_mid = #0; string (string haystack, string needle) str_str = #0; +int str_char (string str, int ind) = #0;