moonbridge

changeset 151:1939ffe973e0

Improved Lua reference code for moonbridge_io.run(...)
author jbe
date Fri May 08 03:35:32 2015 +0200 (2015-05-08)
parents b0e2fbf9d5a8
children 2a5bd37034c6
files reference.txt
line diff
     1.1 --- a/reference.txt	Fri May 08 03:22:15 2015 +0200
     1.2 +++ b/reference.txt	Fri May 08 03:35:32 2015 +0200
     1.3 @@ -384,26 +384,29 @@
     1.4          local work_to_do = false
     1.5          for func, result_handler in pairs(function_set) do
     1.6            ::again::
     1.7 -          local r1, r2, r3, ... = func()
     1.8 -          if r1 == moonbridge_io.block then
     1.9 -            if type(r3) == "string" and string.match(r3, "r") then
    1.10 -              read_fds[r2] = true
    1.11 +          local res = table.pack(func())
    1.12 +          if res[1] == moonbridge_io.block then
    1.13 +            if string.match(res[3], "r") then
    1.14 +              read_fds[res[2]] = true
    1.15              end
    1.16 -            if type(r3) == "string" and string.match(r3, "w") then
    1.17 -              write_fds[r2] = true
    1.18 +            if string.match(res[3], "w") then
    1.19 +              write_fds[res[2]] = true
    1.20              end
    1.21              work_to_do = true
    1.22 -          elseif r1 == moonbridge_io.multiblock then
    1.23 -            for fd, active in pairs(r2) do
    1.24 +          elseif res[1] == moonbridge_io.multiblock then
    1.25 +            for fd, active in pairs(res[2]) do
    1.26                if active then read_fds[fd] = true end
    1.27              end
    1.28 -            for fd, active in pairs(r3) do
    1.29 +            for fd, active in pairs(res[3]) do
    1.30                if active then write_fds[fd] = true end
    1.31              end
    1.32              work_to_do = true
    1.33            else
    1.34 -            if result_handler == true or result_handler(r1, r2, r3, ...) then
    1.35 -              function_set[func] = nil
    1.36 +            if
    1.37 +              result_handler == true or
    1.38 +              result_handler(table.unpack(res, 1, res.n))
    1.39 +            then
    1.40 +              function_set[func] = nil  -- task finished
    1.41              else
    1.42                goto again
    1.43              end

Impressum / About Us