lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Everyone,

I'm attempting to modify the format of the try-catch statement patch
(available at http://lua-users.org/lists/lua-l/2008-01/msg00654.html).

Previously the format of the try-catch was:

try
  -- attempt code
catch e do
  -- catch error
end

However, I want to modify the try-catch so that it can be of the form:

try
  -- attempt code
catch (Engine.DivideByZeroException e) do
  -- catch Engine.DivideByZeroException
catch (Engine.Exception e) do
  -- catch Engine.Exception
end

Now I've successfully modified the parser so that multiple catch
blocks can be written, but I'm having trouble getting the exception
type out of the expression.  Now I can compare types using a
metamethod __type I've written, so don't worry about the type
comparison, but I can't seem to get it to parse the first expression
and then load the error object into the second 'e' value.  The problem
is that the expr() call in the parser seems to overwrite the value
when it's an index of a table (i.e. if Engine.Exception was MyClass,
there's no problem).  In addition, I can't work out how to properly
pass the information from the parser to the virtual machine (I know I
can create new local values with new_localvar(ls, varname, 0), but I
want to read an existing expression and place it somewhere not
accessible to Lua code, but accessible to the LVM so I can read it's
type at runtime and jump if necessary).

I've pasted the trystat() function, called when the parser hits an
'try' token, at http://privatepaste.com/0259e096fb.  Hopefully someone
can inform me as to how I'm meant to read the expression and pass it
to the LVM, as there's pretty much no internal documentation.

I'll be able to check the type in the LVM as long as I can get the
TValue* for both the type expression and the error object, and jump /
execute code if necessary.

Regards, James.