diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-29 12:10:05 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-29 12:10:05 +0200 |
| commit | 5890678289e28cc9e666c1dda8265712bd27ac03 (patch) | |
| tree | 1e5104f5d6e740573066b9df9fa498e27b79e01e /src | |
| parent | d9400c00c05590e0d0e40e6775dc338d28b92f14 (diff) | |
| download | lanes-5890678289e28cc9e666c1dda8265712bd27ac03.tar.gz lanes-5890678289e28cc9e666c1dda8265712bd27ac03.tar.bz2 lanes-5890678289e28cc9e666c1dda8265712bd27ac03.zip | |
Fix lanes.lua dependency on "io"
Diffstat (limited to 'src')
| -rw-r--r-- | src/lanes.lua | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/src/lanes.lua b/src/lanes.lua index 6616667..982de98 100644 --- a/src/lanes.lua +++ b/src/lanes.lua | |||
| @@ -51,12 +51,13 @@ local lanes = {} | |||
| 51 | -- | 51 | -- |
| 52 | local assert = assert(assert) | 52 | local assert = assert(assert) |
| 53 | local error = assert(error) | 53 | local error = assert(error) |
| 54 | local io = assert(io) | ||
| 55 | local pairs = assert(pairs) | 54 | local pairs = assert(pairs) |
| 55 | local string = assert(string, "'string' library not available") | ||
| 56 | local string_gmatch = assert(string.gmatch) | 56 | local string_gmatch = assert(string.gmatch) |
| 57 | local string_format = assert(string.format) | 57 | local string_format = assert(string.format) |
| 58 | local select = assert(select) | 58 | local select = assert(select) |
| 59 | local setmetatable = assert(setmetatable) | 59 | local setmetatable = assert(setmetatable) |
| 60 | local table = assert(table, "'table' library not available") | ||
| 60 | local table_insert = assert(table.insert) | 61 | local table_insert = assert(table.insert) |
| 61 | local tonumber = assert(tonumber) | 62 | local tonumber = assert(tonumber) |
| 62 | local tostring = assert(tostring) | 63 | local tostring = assert(tostring) |
| @@ -64,6 +65,27 @@ local type = assert(type) | |||
| 64 | 65 | ||
| 65 | -- ################################################################################################# | 66 | -- ################################################################################################# |
| 66 | 67 | ||
| 68 | -- for error reporting when debugging stuff | ||
| 69 | --[[ | ||
| 70 | local io = assert(io, "'io' library not available") | ||
| 71 | local function WR(str) | ||
| 72 | io.stderr:write(str.."\n" ) | ||
| 73 | end | ||
| 74 | |||
| 75 | -- ################################################################################################# | ||
| 76 | |||
| 77 | local function DUMP(tbl) | ||
| 78 | if not tbl then return end | ||
| 79 | local str="" | ||
| 80 | for k,v in pairs(tbl) do | ||
| 81 | str= str..k.."="..tostring(v).."\n" | ||
| 82 | end | ||
| 83 | WR(str) | ||
| 84 | end | ||
| 85 | ]] | ||
| 86 | |||
| 87 | -- ################################################################################################# | ||
| 88 | |||
| 67 | local isLuaJIT = (package and package.loaded.jit and jit.version) and true or false | 89 | local isLuaJIT = (package and package.loaded.jit and jit.version) and true or false |
| 68 | 90 | ||
| 69 | local default_params = | 91 | local default_params = |
| @@ -163,23 +185,6 @@ end | |||
| 163 | 185 | ||
| 164 | -- ################################################################################################# | 186 | -- ################################################################################################# |
| 165 | 187 | ||
| 166 | local function WR(str) | ||
| 167 | io.stderr:write(str.."\n" ) | ||
| 168 | end | ||
| 169 | |||
| 170 | -- ################################################################################################# | ||
| 171 | |||
| 172 | local function DUMP(tbl) | ||
| 173 | if not tbl then return end | ||
| 174 | local str="" | ||
| 175 | for k,v in pairs(tbl) do | ||
| 176 | str= str..k.."="..tostring(v).."\n" | ||
| 177 | end | ||
| 178 | WR(str) | ||
| 179 | end | ||
| 180 | |||
| 181 | -- ################################################################################################# | ||
| 182 | |||
| 183 | local valid_libs = | 188 | local valid_libs = |
| 184 | { | 189 | { |
| 185 | ["package"] = true, | 190 | ["package"] = true, |
| @@ -550,7 +555,7 @@ local configure_timers = function() | |||
| 550 | local timer_gateway_batched = timer_gateway.batched | 555 | local timer_gateway_batched = timer_gateway.batched |
| 551 | set_finalizer(function(err, stk) | 556 | set_finalizer(function(err, stk) |
| 552 | if err and type(err) ~= "userdata" then | 557 | if err and type(err) ~= "userdata" then |
| 553 | WR("LanesTimer error: "..tostring(err)) | 558 | error("LanesTimer error: "..tostring(err)) |
| 554 | --elseif type(err) == "userdata" then | 559 | --elseif type(err) == "userdata" then |
| 555 | -- WR("LanesTimer after cancel" ) | 560 | -- WR("LanesTimer after cancel" ) |
| 556 | --else | 561 | --else |
| @@ -585,7 +590,7 @@ local configure_timers = function() | |||
| 585 | end | 590 | end |
| 586 | end | 591 | end |
| 587 | end -- timer_body() | 592 | end -- timer_body() |
| 588 | timer_lane = gen("*", { package= {}, priority = core.max_prio, name = "LanesTimer"}, timer_body)() -- "*" instead of "io,package" for LuaJIT compatibility... | 593 | timer_lane = gen("lanes.core,table", { name = "LanesTimer", package = {}, priority = core.max_prio }, timer_body)() |
| 589 | end -- first_time | 594 | end -- first_time |
| 590 | 595 | ||
| 591 | ----- | 596 | ----- |
| @@ -761,14 +766,6 @@ local configure = function(settings_) | |||
| 761 | setmetatable(lanes, nil) -- remove it | 766 | setmetatable(lanes, nil) -- remove it |
| 762 | lanes.configure = nil -- no need to call configure() ever again | 767 | lanes.configure = nil -- no need to call configure() ever again |
| 763 | 768 | ||
| 764 | -- This check is for sublanes requiring Lanes | ||
| 765 | -- | ||
| 766 | -- TBD: We could also have the C level expose 'string.gmatch' for us. But this is simpler. | ||
| 767 | -- | ||
| 768 | if not string then | ||
| 769 | error("To use 'lanes', you will also need to have 'string' available.", 2) | ||
| 770 | end | ||
| 771 | |||
| 772 | -- now we can configure Lanes core | 769 | -- now we can configure Lanes core |
| 773 | local settings = core.configure and core.configure(params_checker(settings_)) or core.settings | 770 | local settings = core.configure and core.configure(params_checker(settings_)) or core.settings |
| 774 | 771 | ||
