From d8e446dfad1195d0ed3a63e8945a2f96c73f84cc Mon Sep 17 00:00:00 2001
From: Benoit Germain This document was revised on 17-Feb-11, and applies to version 3.1.0
+ This document was revised on 17-Feb-11, and applies to version 3.1.2
Copyright © 2007-12 Asko Kauppi, Benoit Germain. All rights reserved.
Lua Lanes is published under the same MIT license as Lua 5.1.
-
-stack_tbl is an array of "<filename>:<line>" strings, -describing where the error was thrown. Use table.concat() to format -it to your liking (or just ignore it). + +
+ set_error_reporting("basic"|"extended")
+ |
+ Sets the error reporting mode. "basic" is selected by default. +
+ stack_tbl is a table describing where the error was thrown.
+ In extended mode, stack_tbl is an array of tables containing info gathered with lua_getinfo() ("source","currentline","name","namewhat","what").
+In "basic mode", stack_tbl is an array of "<filename>:<line>" strings. Use table.concat() to format it to your liking (or just ignore it).
+
If you use :join, make sure your lane main function returns
a non-nil value so you can tell timeout and error cases apart from succesful
diff --git a/src/lanes.c b/src/lanes.c
index 176009a..d777be1 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -51,7 +51,7 @@
* ...
*/
-char const* VERSION = "3.1.1";
+char const* VERSION = "3.1.2";
/*
===============================================================================
@@ -107,10 +107,6 @@ THE SOFTWARE.
*/
#define ERROR_FULL_STACK
-#ifdef ERROR_FULL_STACK
-# define STACK_TRACE_KEY ((void*)lane_error) // used as registry key
-#endif
-
// NOTE: values to be changed by either thread, during execution, without
// locking, are marked "volatile"
//
@@ -695,10 +691,11 @@ LUAG_FUNC( linda_deep ) {
LUAG_FUNC( linda_tostring)
{
char text[32];
- struct s_Linda *linda = lua_toLinda( L, 1);
+ int len;
+ struct s_Linda* linda = lua_toLinda( L, 1);
luaL_argcheck( L, linda, 1, "expected a linda object!");
- sprintf( text, "linda: %p", linda);
- lua_pushstring( L, text);
+ len = sprintf( text, "linda: %p", linda);
+ lua_pushlstring( L, text, len);
return 1;
}
@@ -720,15 +717,15 @@ LUAG_FUNC( linda_concat)
if ( linda1)
{
char text[32];
- sprintf( text, "linda: %p", linda1);
- lua_pushstring( L, text);
+ int len = sprintf( text, "linda: %p", linda1);
+ lua_pushlstring( L, text, len);
lua_replace( L, 1);
}
if ( linda2)
{
char text[32];
- sprintf( text, "linda: %p", linda2);
- lua_pushstring( L, text);
+ int len = sprintf( text, "linda: %p", linda2);
+ lua_pushlstring( L, text, len);
lua_replace( L, 2);
}
// concat the result
@@ -1281,58 +1278,118 @@ LUAG_FUNC( _single ) {
*/
#ifdef ERROR_FULL_STACK
-static int lane_error( lua_State *L ) {
- lua_Debug ar;
- unsigned lev,n;
+# define STACK_TRACE_KEY ((void*)lane_error) // used as registry key
+# define EXTENDED_STACK_TRACE_KEY ((void*)LG_set_error_reporting) // used as registry key
+
+#ifdef ERROR_FULL_STACK
+LUAG_FUNC( set_error_reporting)
+{
+ bool_t equal;
+ luaL_checktype( L, 1, LUA_TSTRING);
+ lua_pushliteral( L, "extended");
+ equal = lua_rawequal( L, -1, 1);
+ lua_pop( L, 1);
+ if( equal)
+ {
+ goto done;
+ }
+ lua_pushliteral( L, "basic");
+ equal = !lua_rawequal( L, -1, 1);
+ lua_pop( L, 1);
+ if( equal)
+ {
+ return luaL_error( L, "unsupported error reporting model");
+ }
+done:
+ lua_pushlightuserdata( L, EXTENDED_STACK_TRACE_KEY);
+ lua_pushboolean( L, equal);
+ lua_rawset( L, LUA_REGISTRYINDEX);
+ return 0;
+}
+#endif // ERROR_FULL_STACK
+
+static int lane_error( lua_State* L)
+{
+ lua_Debug ar;
+ unsigned lev, n;
+ bool_t extended;
- // [1]: error message (any type)
+ // [1]: error message (any type)
- assert( lua_gettop(L)==1 );
+ assert( lua_gettop( L) == 1);
- // Don't do stack survey for cancelled lanes.
- //
+ // Don't do stack survey for cancelled lanes.
+ //
#if 1
- if (lua_touserdata(L,1) == CANCEL_ERROR)
- return 1; // just pass on
+ if( lua_touserdata( L, 1) == CANCEL_ERROR)
+ return 1; // just pass on
#endif
- // Place stack trace at 'registry[lane_error]' for the 'luc_pcall()'
- // caller to fetch. This bypasses the Lua 5.1 limitation of only one
- // return value from error handler to 'lua_pcall()' caller.
+ lua_pushlightuserdata( L, EXTENDED_STACK_TRACE_KEY);
+ lua_gettable( L, LUA_REGISTRYINDEX);
+ extended = lua_toboolean( L, -1);
+ lua_pop( L, 1);
- // It's adequate to push stack trace as a table. This gives the receiver
- // of the stack best means to format it to their liking. Also, it allows
- // us to add more stack info later, if needed.
- //
- // table of { "sourcefile.lua: