rzel / kahlua

Automatically exported from code.google.com/p/kahlua
0 stars 0 forks source link

string.len() fails? #26

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In my program I've the effect, that string.len() always fails?

Code:
    print ("original ID: ",id)
    id = string.sub(id,3)  -- remove the leading 0x
    print ("reduced ID: ",id)
    numID=tonumber(id)
    print ("numID: ",numID)
    ascID=tostring(numID % 256 , 16 )
    print ("ascID: ",ascID)
    print ("Len: ",string.len(ascID))  --- this is line 287 

gives the effect:

original ID:         0x4
reduced ID:         4
numID:         4
ascID:         4
Crash: Tried to call nil
at @HHOpen.lua:287

java.lang.RuntimeException: Tried to call nil
        at se.krka.kahlua.stdlib.BaseLib.fail(BaseLib.java:390)
        at se.krka.kahlua.stdlib.BaseLib.luaAssert(BaseLib.java:385)
        at se.krka.kahlua.vm.LuaState.luaMainloop(LuaState.java:667)
        at se.krka.kahlua.vm.LuaState.call(LuaState.java:217)
        at se.krka.kahlua.vm.LuaState.pcall(LuaState.java:1297)
        at se.krka.kahlua.vm.LuaState.pcall(LuaState.java:1276)
        ...

the same exception happens also on other places where I try the string.len() 
function.

any ideas?

regards

Steffen

Original issue reported on code.google.com by steffen....@gmail.com on 17 Jul 2010 at 6:56

GoogleCodeExporter commented 8 years ago
The problem is most likely that you've failed to load stdlib.lua (or 
stdlib.lbc), where string.len is defined.

Original comment by kristofer.karlsson@gmail.com on 17 Jul 2010 at 7:22

GoogleCodeExporter commented 8 years ago
Hello Kristofer,
not loading the stdlib.lbc would be a good explanation, but I don't get an 
error message while loading the stdlib.lbc, and I also use other functions of 
the string lib like string.sub or string.byte without problems

but when I replace string.len(something) against #something, it works.. Looks 
strange to me

Original comment by steffen....@gmail.com on 18 Jul 2010 at 6:02

GoogleCodeExporter commented 8 years ago
string.sub and string.byte are defined in Java, not in stdlib.lua

Original comment by kristofer.karlsson@gmail.com on 18 Jul 2010 at 7:11