Changeset 135 for trunk/lua/cli.lua


Ignore:
Timestamp:
02/05/2012 05:36:52 AM (16 months ago)
Author:
reyalp
Message:

use xpcall to trap errors in cli commands, show stack trace by default
add simple table average function table_amean to util

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lua/cli.lua

    r134 r135  
    228228                                return false,msg 
    229229                        end 
     230                        local cstatus 
    230231                        local t0=ustime.new() 
    231                         status,msg = self.names[cmd](args) 
     232                        cstatus,status,msg = xpcall( 
     233                                function() 
     234                                        return self.names[cmd](args) 
     235                                end, 
     236                                util.err_traceback) 
    232237                        if cli.showtime then 
    233238                                printf("time %.4f\n",ustime.diff(t0)/1000000) 
     239                        end 
     240                        if not cstatus then 
     241                                return false,status 
    234242                        end 
    235243                        if not status and not msg then 
     
    316324                        local f,r = loadstring(args) 
    317325                        if f then 
    318                                 r={pcall(f)}; 
     326                                r={xpcall(f,util.err_traceback)} 
    319327                                if not r[1] then  
    320328                                        return false, string.format("call failed:%s\n",r[2]) 
Note: See TracChangeset for help on using the changeset viewer.