Getting LUA error msg

BlitzMax Forums/BlitzMax Beginners Area/Getting LUA error msg

Hezkore(Posted 2008) [#1]
Anyone know how to get an error message from LUA?

I'm not calling any functions from LUA, I'm simply running a LUA script via lua_dofile(LuaState, "test.lua") and nothing really happens if there's a syntax error or something, I'd like to print LUA errors but can't figure out how to actually GET the error messages from LUA.


Zeke(Posted 2008) [#2]
If luaL_dofile(luastate,"test.lua")
Print "[ERROR] "+lua_tostring(luastate,-1)
EndIf


Hezkore(Posted 2008) [#3]
Well... *cough* that was easy, heh.
Thanks for the straight forward answer mate. :]


Htbaa(Posted 2008) [#4]
It returns true when an error occurred? Are you sure?


Hezkore(Posted 2008) [#5]
It returns the whole error message, it works perfectly.


Gabriel(Posted 2008) [#6]
It returns true when an error occurred? Are you sure?

Yes. If there were no errors, it returns 0.


Htbaa(Posted 2008) [#7]
That doesn't make sense at all...


plash(Posted 2008) [#8]
Yes it does.

If an error occurred, luaL_dofile() returns True.
If there were no errors, luaL_dofile() returns False.

http://pgl.yoyo.org/luai/i/luaL_dofile


Htbaa(Posted 2008) [#9]
It makes more sense to say

If Not luaL_dofile(luaState, "test.lua")
'Error occurred
End If

Imo the current way is reversed logic...


Hezkore(Posted 2008) [#10]
Does any of you know how to store a LUA function in my field?
I've tried to use lua_tocfunction() but can't get it to really work...
What I basically want to do is have a button in BlitzMax as the type Gadget with a field called Func() and then in LUA do something like

function Clicked()
print("Hey!")
end

gadgetfunction(Clicked)

Which would set my Func() field into the LUA function Clicked(), then when I click the button just call Func()

I guess what I'm asking is... how do I pass a function as a parameter in LUA?