LUA - CheckString

BlitzMax Forums/BlitzMax Beginners Area/LUA - CheckString

Craftler(Posted 2007) [#1]
SuperStrict
Import axe.luascript
Import axe.lua

Global scriptEnv:TLuaScriptEngine = New TLuaScriptEngine
scriptEnv.Reset()

Function LUA_Greet1:Int( luastate:Byte Ptr )
Local name$=scriptEnv.CheckString(-1)
Print("Hello, "+name$+"!")
Return 1
End Function

scriptEnv.AddFunction(LUA_Greet1,"F_GreetTest1")

scriptEnv.setscripttext("F_GreetTest1('Test')","")

scriptEnv.runscript()

scriptEnv.ShutDown()

Need help... when i start it, it print:
Hello, @èc!
PLz help me


Wiering(Posted 2007) [#2]
For me it gave:
Hello, Test
But then I synchronized modules and after that it didn't work anymore.


Habatar(Posted 2007) [#3]
Hello.

I'm having the same problem.
I have find a solution that seems to work correctly.

Use:
Local MyString:String = luaL_checkstring( scriptEnv.m_lua_state, 1)


or

Local MyString:String = String.FromCString(luaL_checkstring(scriptEnv.m_lua_state, 1))

This last is the same as the code for the function CheckString(). But its work and If I use the function not work.


patmaba(Posted 2007) [#4]
I have the same problem.

After i have installed mingw 3.1.

I have run your original code without modufication.

Now, the output work fine "Hello, Test"


Rozek(Posted 2007) [#5]
Habatar,

as far as I understand the interfacing mechanisms of BlitzMax, you should not need the explicit string conversion "String.fromCString" when using "luaL_checkstring" - it should be done automatically...


Craftler(Posted 2007) [#6]
Yeah! Thx... now it works perfectly :)

Function CheckString:String(scr:TLuaScriptEngine)
Return string.fromCString(lual_checkstring(scr.m_lua_state,1))
End Function