Fix string.len (includes new tests.)

This commit is contained in:
Ian Farmer
2008-06-02 05:53:32 +00:00
parent ef2c087c1b
commit 60323962f7
2 changed files with 10 additions and 1 deletions

View File

@@ -395,7 +395,7 @@ public class StringLib extends LFunction {
* Embedded zeros are counted, so "a\000bc\000" has length 5.
*/
static void len( LuaState vm ) {
int l = vm.tostring(2).length();
int l = vm.tolstring(2).length();
vm.resettop();
vm.pushinteger( l );
}

View File

@@ -68,3 +68,12 @@ t( 'abc' )
t( 'ab' )
t( 'a' )
t( '' )
print(string.len("Hello, world"))
print(#"Hello, world")
print(string.len("\0\0\0"))
print(#"\0\0\0")
print(string.len("\0\1\2\3"))
print(#"\0\1\2\3")
local s = "\194\161Hola!"
print(s, string.len(s), #s)