Changeset 40


Ignore:
Timestamp:
05/01/2011 11:41:27 PM (2 years ago)
Author:
reyalP
Message:

allow strings for single rlib names, comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lua/chdku.lua

    r39 r40  
    5151        libs={}, 
    5252} 
    53  
    5453--[[ 
    5554register{ 
    5655        name='libname' 
    57         depend={'lib1','lib2'...}, -- already registered rlibs this one requires (cyclic deps not allowed) 
     56        depend='lib'|{'lib1','lib2'...}, -- already registered rlibs this one requires (cyclic deps not allowed) 
    5857        code='', -- main lib code. 
    5958} 
    6059]] 
    6160function rlibs:register(t) 
    62         if type(t.depend) == 'nil' then 
     61        -- for convenience, single lib may be given as string 
     62        if type(t.depend) == 'string' then 
     63                t.depend = {t.depend} 
     64        elseif type(t.depend) == 'nil' then 
    6365                t.depend = {} 
    6466        elseif type(t.depend) ~= 'table' then 
    65                 error('expected dependency table') 
     67                error('expected dependency table or string') 
    6668        end 
    6769        if type(t.code) ~= 'string' then 
     
    108110--[[ 
    109111return a list of rlibs in dependency order 
     112t=rlibs:build_list('name'|{'name1','name2',...}) 
    110113]] 
    111114function rlibs:build_list(libnames) 
     115        -- single can be given as string 
     116        if type(libnames) == 'string' then 
     117                libnames={libnames} 
     118        elseif type(libnames) ~= 'table' then 
     119                error('rlibs:build_list expected string or table for libnames') 
     120        end 
    112121        local build={ 
    113122                list={}, 
     
    121130--[[ 
    122131return a string containing all the required rlib code 
     132code=rlibs:build('name'|{'name1','name2',...}) 
    123133]] 
    124134function rlibs:build(names) 
     
    187197        end 
    188198end 
    189  
    190199serialize_defaults = { 
    191200        maxdepth=10, 
     
    194203        pretty=false, 
    195204} 
    196  
    197205function serialize(v,opts) 
    198206        if opts then 
     
    212220{ 
    213221        name='serialize_msgs', 
    214         depend={'serialize'}, 
     222        depend='serialize', 
    215223        code=[[ 
    216224        usb_msg_table_to_string=serialize 
     
    258266{ 
    259267        name='msg_batcher', 
    260         depend={'serialize_msgs'}, 
     268        depend='serialize_msgs', 
    261269        code=[[ 
    262270function msg_batcher(opts_in) 
     
    299307{ 
    300308        name='ls_simple', 
    301         depend={'msg_batcher'}, 
     309        depend='msg_batcher', 
    302310        code=[[ 
    303311function ls_simple(path) 
     
    347355{ 
    348356        name='ls', 
    349         depend={'serialize_msgs'}, 
     357        depend='serialize_msgs', 
    350358        code=[[ 
    351359function ls(path,opts_in) 
     
    418426                { 
    419427                        wait=true, 
    420                         libs={'ls'}, 
     428                        libs='ls', 
    421429                        msgs=function(msg) 
    422430                                if msg.subtype ~= 'table' then 
     
    482490                -- syntax error, try to fetch the error message 
    483491                if err == 'syntax' then 
     492                        -- TODO extract error line and match with code 
    484493                        local msg = chdku.get_error_msg() 
    485494                        if msg then 
     
    531540                                else 
    532541                                        -- if serialize_msgs is not selected, table return values will be strings 
     542                                        -- TODO not updated for new rlib yet 
    533543                                        if msg.subtype == 'table' and in_table(opts.libs,'serialize_msgs') then 
    534544                                                results[i] = unserialize(msg.value) 
Note: See TracChangeset for help on using the changeset viewer.