Changeset 5137

Show
Ignore:
Timestamp:
07/25/09 03:57:13 (4 years ago)
Author:
jow
Message:

libs/core: support udata util.striptags(), optimizie copcall implementation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/core/luasrc/util.lua

    r5114 r5137  
    216216-- @return  String with HTML tags stripped of 
    217217function striptags(s) 
    218     return pcdata(s:gsub("</?[A-Za-z][A-Za-z0-9:_%-]*[^>]*>", " "):gsub("%s+", " ")) 
     218    return pcdata(tostring(s):gsub("</?[A-Za-z][A-Za-z0-9:_%-]*[^>]*>", " "):gsub("%s+", " ")) 
    219219end 
    220220 
     
    769769 
    770770-- Handle return value of protected call 
    771 function handleReturnValue(err, co, status, ...) 
     771function handleReturnValue(err, co, status, arg1, arg2, arg3, arg4, arg5) 
    772772    if not status then 
    773         return false, err(debug.traceback(co, (...)), ...) 
    774     end 
    775     if coroutine.status(co) == 'suspended' then 
    776         return performResume(err, co, coroutine.yield(...)) 
    777     else 
    778         return true, ... 
    779     end 
     773        return false, err(debug.traceback(co, arg1), arg1, arg2, arg3, arg4, arg5) 
     774    end 
     775 
     776    if coroutine.status(co) ~= 'suspended' then 
     777        return true, arg1, arg2, arg3, arg4, arg5 
     778    end 
     779 
     780    return performResume(err, co, coroutine.yield(arg1, arg2, arg3, arg4, arg5)) 
    780781end 
    781782 
    782783-- Resume execution of protected function call 
    783 function performResume(err, co, ...) 
    784     if get_memory_limit and get_memory_limit() > 0 and 
    785        collectgarbage("count") > (get_memory_limit() * 0.8) 
    786     then 
    787         collectgarbage("collect") 
    788     end 
    789  
    790     return handleReturnValue(err, co, coroutine.resume(co, ...)) 
    791 end 
     784function performResume(err, co, arg1, arg2, arg3, arg4, arg5) 
     785    return handleReturnValue(err, co, coroutine.resume(co, arg1, arg2, arg3, arg4, arg5)) 
     786end