lua-users home
lua-l archive

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


Hi list,

How do I write a "non-trapping" version of the "dostring" function
that will propagates errors instead of just returning a nil and an error
string? The default behaviour is that this code

  lua -e '
    print(dostring("return 1, 2"))   --> 1       2
    print(dostring("return"))        --> userdata(0): 0x804f658
    print(dostring("return nil"))    --> nil
    print(dostring("foo()"))         --> [error, then:] nil     run-time error
    print("Program continues...")
    print(dostring("return nil, \"run-time error\""))
  '

gives this output:

  1       2
  userdata(0): 0x804f658
  nil
  error: attempt to call global `foo' (a nil value)
  stack traceback:
     1:  main of string "foo()" at line 1
     2:  function `dostring' [C]
     3:  main of string "..." at line 5
  nil     run-time error
  Program continues...
  nil     run-time error

and I'd like to have a "hard_dostring" function that would act as
"dostring" but would return nothing in a case like
'print(hard_dostring("return"))', and would make the program abort in
a case like 'print(dostring("foo()"))'...

C solutions would be fine... BTW, I'm using Lua-4.0 on an i386 running
Debian GNU/Linux.

  Cheers, and thanks in advance,
    Eduardo Ochs
    http://angg.twu.net/
    http://angg.twu.net/index.html#lua