Lua and Errors
Hey, is there any way to get lua to report compile or syntax error to the host program? I've used the panic function and that works for some errors, but if I try to call a function that does not exist, then it doesn't work. Instead it just (I guess) outputs the error message ("trying to call nil value") to the stdout. Are there any way of catching these errors?
Also, I while back I saw someone post some code somewhere that would print out the globals table and it's values. Is there any easy way of doing this? can you post some code please?
Thanks all.
Denny.
As for the second question:
table.foreach(_G, print)
table.foreach is an algorithm which takes a table, and a function. It iterates over the table, calling the function with each key/value pair. Print, of course, just prints out whatever is passed in. _G is an alias for the global table.
table.foreach(_G, print)
table.foreach is an algorithm which takes a table, and a function. It iterates over the table, calling the function with each key/value pair. Print, of course, just prints out whatever is passed in. _G is an alias for the global table.
Thanks for the second part, I'll try it soon. For the first part, lua_pcall is only for calling functions. what if I do lua_dofile? then my lua script looks like this:
--Lua Test Program
Brain21( "this causes an error" )
--End file
there is no function Brain21 defined, so it will give me an error, but not one that I can catch (so far). Is there a way?
Denny.
--Lua Test Program
Brain21( "this causes an error" )
--End file
there is no function Brain21 defined, so it will give me an error, but not one that I can catch (so far). Is there a way?
Denny.
lua_dofile is kind of deprecated. You should prefer luaL_loadfile, followed by lua_call (or lua_pcall).
In Lua 5.0 register a function called _ALERT.
This function will get called with the error string as the only parameter.
This function will get called with the error string as the only parameter.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement