[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Error handling
- From: LEGO <luis.ontanon@...>
- Date: Thu, 16 Feb 2006 22:53:10 +0100
Agreed, If we could throw tables, or other types it would be much better.
On 2/16/06, Chris <coderight@gmail.com> wrote:
> The problem with string error messages can be pointed at in your own
> example:
> > elseif problem == "radiu failure"
That's a typo and you can make one in a lua type and it migh not be
noticed by the compiler. Lua is not "strict" language that certainly
doesn't help. Shit happens in every language (human too),
> Numeric error codes (or other "fixed" types like an exception) are much
> more useful for error handling in code. The strings are good for the end
> user for sure but code needs a little more.
[id-est:~] lego% src/lua-5.1/src/lua
Lua 5.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
> print("5"+2)
7
> a = 7
> b = 8
> print (a..b)
78
> ^D
You can use numbers as well if you prefer... like in perl numbers are
strings and strings can be numbers. ( I got a headache with
luaL_optstring() 'till I did not understand this)
> This is especially true when dealing with multiple languages like I am. I
> have a Lua backend interfacing to C, XML-RPC, and JavaScript. The text
> messages are just not reliable enough with all these systems in play (versus
> numeric codes which would be easy to deal with in all those systems).
...
lua_error(L,"\xff\x01your error code");
...
int handler(L) {
const char* err = lua_tostring(L,1);
if ( *err == '\xff' ) switch (*(err+1)) {
case '\x01':
case '\x02':
}
}
This trick might help.
Luis
--
This information is top security. When you have read it, destroy yourself.
-- Marshall McLuhan