LUA - CheckString

BlitzMax Forums/BlitzMax Beginners Area/LUA - CheckString

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

For me it gave:
Hello, Test
But then I synchronized modules and after that it didn't work anymore.

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.

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"

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...

Yeah! Thx... now it works perfectly :)

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