Skip to content

Commit ca4ab45

Browse files
committed
Updated the table2string method in LuaStepper.c and lStepper.lua. updated the rockspec
1 parent 97dcfec commit ca4ab45

File tree

5 files changed

+128
-132
lines changed

5 files changed

+128
-132
lines changed

LuaStepper.c

Lines changed: 78 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define urgentTasks 2
3030
#define LS_DEFSTEPS 10
3131

32-
#define VERSION "1.14.07.12"
32+
#define VERSION "1.16.06.17"
3333

3434
struct Task
3535
{
@@ -374,86 +374,83 @@ static int addTask(lua_State *L)
374374

375375
msg = "_LS={} "
376376
"function _LS.tableToString(t) "
377-
" if type(t) ~= 'table' then return nil, 'Expected table parameter' end "
378-
" local rL = {cL = 1} "
379-
" rL[rL.cL] = {} "
380-
" local tabIndex = {} "
381-
" local latestTab = 0 "
382-
" do "
383-
" rL[rL.cL]._f,rL[rL.cL]._s,rL[rL.cL]._var = pairs(t) "
384-
" rL[rL.cL].str = 't0={}' "
385-
" rL[rL.cL].t = t "
386-
" rL[rL.cL].tabIndex = 0 "
387-
" tabIndex[t] = rL[rL.cL].tabIndex "
388-
" while true do "
389-
" local key "
390-
" local k,v = rL[rL.cL]._f(rL[rL.cL]._s,rL[rL.cL]._var) "
391-
" rL[rL.cL]._var = k "
392-
" if not k and rL.cL == 1 then "
393-
" break "
394-
" elseif not k then "
395-
" rL[rL.cL-1].str = rL[rL.cL-1].str..'\\n'..rL[rL.cL].str "
396-
" rL.cL = rL.cL - 1 "
397-
" if rL[rL.cL].vNotDone then "
398-
" key = 't'..rL[rL.cL].tabIndex..'[t'..tostring(rL[rL.cL+1].tabIndex)..']' "
399-
" rL[rL.cL].str = rL[rL.cL].str..'\\n'..key..'=' "
400-
" v = rL[rL.cL].vNotDone "
401-
" end "
402-
" rL[rL.cL+1] = nil "
403-
" else "
404-
" if type(k) == 'number' then "
405-
" key = 't'..rL[rL.cL].tabIndex..'['..tostring(k)..']' "
406-
" rL[rL.cL].str = rL[rL.cL].str..'\\n'..key..'=' "
407-
" elseif type(k) == 'string' then "
408-
" key = 't'..rL[rL.cL].tabIndex..'.'..tostring(k) "
409-
" rL[rL.cL].str = rL[rL.cL].str..'\\n'..key..'=' "
410-
" else "
411-
" if tabIndex[k] then "
412-
" key = 't'..rL[rL.cL].tabIndex..'[t'..tabIndex[k]..']' "
413-
" rL[rL.cL].str = rL[rL.cL].str..'\\n'..key..'=' "
414-
" else "
415-
" latestTab = latestTab + 1 "
416-
" rL[rL.cL].str = rL[rL.cL].str..'\\nt'..tostring(latestTab)..'={}' "
417-
" rL[rL.cL].vNotDone = v "
418-
" rL.cL = rL.cL + 1 "
419-
" rL[rL.cL] = {} "
420-
" rL[rL.cL]._f,rL[rL.cL]._s,rL[rL.cL]._var = pairs(k) "
421-
" rL[rL.cL].tabIndex = latestTab "
422-
" rL[rL.cL].t = k "
423-
" rL[rL.cL].str = '' "
424-
" tabIndex[k] = rL[rL.cL].tabIndex "
425-
" end "
426-
" end "
427-
" end "
428-
" if key then "
429-
" rL[rL.cL].vNotDone = nil "
430-
" if type(v) == 'table' then "
431-
" if tabIndex[v] then "
432-
" rL[rL.cL].str = rL[rL.cL].str..'t'..tabIndex[v] "
433-
" else "
434-
" latestTab = latestTab + 1 "
435-
" rL[rL.cL].str = rL[rL.cL].str..'{}' "
436-
" rL[rL.cL].str = rL[rL.cL].str..'\\nt'..tostring(latestTab)..'='..key "
437-
" rL.cL = rL.cL + 1 "
438-
" rL[rL.cL] = {} "
439-
" rL[rL.cL]._f,rL[rL.cL]._s,rL[rL.cL]._var = pairs(v) "
440-
" rL[rL.cL].tabIndex = latestTab "
441-
" rL[rL.cL].t = v "
442-
" rL[rL.cL].str = '' "
443-
" tabIndex[v] = rL[rL.cL].tabIndex "
444-
" end "
445-
" elseif type(v) == 'number' then "
446-
" rL[rL.cL].str = rL[rL.cL].str..tostring(v) "
447-
" elseif type(v) == 'boolean' then "
448-
" rL[rL.cL].str = rL[rL.cL].str..tostring(v) "
449-
" else "
450-
" rL[rL.cL].str = rL[rL.cL].str..string.format('%q',tostring(v)) "
451-
" end "
452-
" end "
453-
" end "
454-
" end "
455-
" return rL[rL.cL].str "
456-
"end "
377+
" if type(t) ~= 'table' then return nil, 'Expected table parameter' end "
378+
" local rL = {cL = 1} "
379+
" rL[rL.cL] = {} "
380+
" local tabIndex = {} "
381+
" local latestTab = 0 "
382+
" local result = {} "
383+
" do "
384+
" rL[rL.cL]._f,rL[rL.cL]._s,rL[rL.cL]._var = pairs(t) "
385+
" result[#result + 1] = 't0={}' "
386+
" rL[rL.cL].t = t "
387+
" rL[rL.cL].tabIndex = 0 "
388+
" tabIndex[t] = rL[rL.cL].tabIndex "
389+
" while true do "
390+
" local key "
391+
" local k,v = rL[rL.cL]._f(rL[rL.cL]._s,rL[rL.cL]._var) "
392+
" rL[rL.cL]._var = k "
393+
" if not k and rL.cL == 1 then "
394+
" break "
395+
" elseif not k then "
396+
" rL.cL = rL.cL - 1 "
397+
" if rL[rL.cL].vNotDone then "
398+
" key = 't'..rL[rL.cL].tabIndex..'[t'..tostring(rL[rL.cL+1].tabIndex)..']' "
399+
" result[#result + 1] = '\\n'..key..'=' "
400+
" v = rL[rL.cL].vNotDone "
401+
" end "
402+
" rL[rL.cL+1] = nil "
403+
" else "
404+
" if type(k) == 'number' then "
405+
" key = 't'..rL[rL.cL].tabIndex..'['..tostring(k)..']' "
406+
" result[#result + 1] = '\\n'..key..'=' "
407+
" elseif type(k) == 'string' then "
408+
" key = 't'..rL[rL.cL].tabIndex..'.'..tostring(k) "
409+
" result[#result + 1] = '\\n'..key..'=' "
410+
" else "
411+
" if tabIndex[k] then "
412+
" key = 't'..rL[rL.cL].tabIndex..'[t'..tabIndex[k]..']' "
413+
" result[#result + 1] = '\\n'..key..'=' "
414+
" else "
415+
" latestTab = latestTab + 1 "
416+
" result[#result + 1] = '\\nt'..tostring(latestTab)..'={}' "
417+
" rL[rL.cL].vNotDone = v "
418+
" rL.cL = rL.cL + 1 "
419+
" rL[rL.cL] = {} "
420+
" rL[rL.cL]._f,rL[rL.cL]._s,rL[rL.cL]._var = pairs(k) "
421+
" rL[rL.cL].tabIndex = latestTab "
422+
" rL[rL.cL].t = k "
423+
" tabIndex[k] = rL[rL.cL].tabIndex "
424+
" end "
425+
" end "
426+
" end "
427+
" if key then "
428+
" rL[rL.cL].vNotDone = nil "
429+
" if type(v) == 'table' then "
430+
" if tabIndex[v] then "
431+
" result[#result + 1] = 't'..tabIndex[v] "
432+
" else "
433+
" latestTab = latestTab + 1 "
434+
" result[#result + 1] = '{}\nt'..tostring(latestTab)..'='..key "
435+
" rL.cL = rL.cL + 1 "
436+
" rL[rL.cL] = {} "
437+
" rL[rL.cL]._f,rL[rL.cL]._s,rL[rL.cL]._var = pairs(v) "
438+
" rL[rL.cL].tabIndex = latestTab "
439+
" rL[rL.cL].t = v "
440+
" tabIndex[v] = rL[rL.cL].tabIndex "
441+
" end "
442+
" elseif type(v) == 'number' then "
443+
" result[#result + 1] = tostring(v) "
444+
" elseif type(v) == 'boolean' then "
445+
" result[#result + 1] = tostring(v) "
446+
" else "
447+
" result[#result + 1] = string.format('%q',tostring(v)) "
448+
" end "
449+
" end "
450+
" end "
451+
" end "
452+
" return table.concat(result) "
453+
"end "
457454
"do"
458455
" local pack = package "
459456
" local req = require "

lStepper.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local string = string
1313
local package = package
1414

1515

16-
local ver = "1.14.07.12" -- Should correspond to the version of the C module
16+
local ver = "1.16.06.17" -- Should correspond to the version of the C module
1717

1818
-- Create the module table here
1919
local M = {}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package = "LuaStepper"
2-
version = "1.14.07.12-1"
2+
version = "1.16.06.17-1"
33
source = {
44
url = "git://github.com/aryajur/LuaStepper.git",
5-
tag = "1.14.07"
5+
tag = "1.16.06"
66
}
77
description = {
88
summary = "Allow Lua scripts to run multiple Lua scripts in parallel, platform independent without using threading.",
99
detailed = [[
10-
C module to allow a Lua state to run multiple Lua scripts in parallel. This is platform independent and will work wherever Lua works. LuaStepper is a module to help lua programs control simultaneous execution of multiple Lua threads without them needing to be coroutines.
10+
LuaStepper is a module to help lua programs control simultaneous execution of multiple Lua threads without them needing to be coroutines. So it is like pre-emptive multitasking but instead of the operating system controlling the task switch and time slicing the Lua parent process does that with the API of this module.
1111
]],
1212
homepage = "http://www.amved.com/milindsweb/LuaStepper.html",
1313
license = "MIT"

test/demo.lua

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
LuaStepper = require("lStepper")
2-
print("LuaStepper version is:",LuaStepper._VERSION)
1+
lStepper = require("lStepper")
2+
print("lStepper version is:",lStepper._VERSION)
33

44
-- Define script 1
55
script1 = [[
66
while true do
77
print('A')
88
end]]
99
-- Add script 1 to the queue with some print statements that are executed immediately
10-
print("Add script 1. ID is -->",LuaStepper.addTask(script1,"print('Initialization step 1') print('Initialization step 2')"))
10+
print("Add script 1. ID is -->",lStepper.addTask(script1,"print('Initialization step 1') print('Initialization step 2')"))
1111

1212
-- Define script 2
1313
script2 = "while true do print('B') end"
1414
-- Add script 2 to the queue with some print statements that are executed immediately
15-
print("Add script 2. ID is -->",LuaStepper.addTask(script2,"print('Initialization step x') print('Initialization step y')"))
15+
print("Add script 2. ID is -->",lStepper.addTask(script2,"print('Initialization step x') print('Initialization step y')"))
1616

1717
-- Define script 3
1818
script3 = [[
@@ -34,13 +34,12 @@ script3 = [[
3434
end
3535
end]]
3636
-- Add script 3 to the queue with a print statement initialization and a variable setting that is then printed in the script
37-
print("Add script 3. ID is -->",LuaStepper.addTask(script3,"print('Adding Script 3') test5='script3'",5,true)) -- 5 means the number os codes to execute for each step of this script
37+
print("Add script 3. ID is -->",lStepper.addTask(script3,"print('Adding Script 3') test5='script3'",5,true)) -- 5 means the number os codes to execute for each step of this script
3838
-- This script is also placed in the urgent task pile by setting true
39-
40-
print("Number of tasks=",LuaStepper.getNumOfTasks()) -- displays 2 1 -- 2 regular 1 urgent
39+
print("Number of tasks=",lStepper.getNumOfTasks()) -- displays 2 1 -- 2 regular 1 urgent
4140
print("Start stepper loop")
4241
for i=1,50 do
43-
x,y=LuaStepper.runLoop() -- Run all the tasks for 1 step
42+
x,y=lStepper.runLoop() -- Run all the tasks for 1 step
4443
if not x then
4544
print(y)
4645
break
@@ -50,26 +49,26 @@ for i=1,50 do
5049
break
5150
end
5251
if i==5 then
53-
print("i=5, script 1 status is ",LuaStepper.taskStatus(0))
54-
print("i=5, script 2 status is ",LuaStepper.taskStatus(1))
52+
print("i=5, script 1 status is ",lStepper.taskStatus(0))
53+
print("i=5, script 2 status is ",lStepper.taskStatus(1))
5554
end
5655
if i==30 then
57-
print("i=30, script 1 status is ",LuaStepper.taskStatus(0))
58-
print("i=30, script 2 status is ",LuaStepper.taskStatus(1))
56+
print("i=30, script 1 status is ",lStepper.taskStatus(0))
57+
print("i=30, script 2 status is ",lStepper.taskStatus(1))
5958
end
6059
if i==20 then
6160
print("B suspended")
62-
LuaStepper.suspendTask(1)
61+
lStepper.suspendTask(1)
6362
end
6463
if i==40 then
6564
print("B resumed")
66-
LuaStepper.resumeTask(1)
65+
lStepper.resumeTask(1)
6766
end
6867
if i==5 then
69-
x,y = LuaStepper.getTaskData(4,"test3") -- Get the value of test3 from script 3
68+
x,y = lStepper.getTaskData(4,"test3") -- Get the value of test3 from script 3
7069
if x then
7170
print("Value from script3 test3=",x)
72-
print(LuaStepper.setTaskData(4,{test4=x})) -- Set value of test4 to be same as test3 in script 3
71+
print(lStepper.setTaskData(4,{test4=x})) -- Set value of test4 to be same as test3 in script 3
7372
else
7473
print("Error getting data:",y)
7574
end
@@ -78,8 +77,8 @@ for i=1,50 do
7877
local t = {
7978
test6='Added Table!'
8079
}
81-
print(LuaStepper.setTaskData(4,{test5=t}))
82-
x=LuaStepper.getTaskData(4,"test10")
80+
print(lStepper.setTaskData(4,{test5=t}))
81+
x=lStepper.getTaskData(4,"test10")
8382
print(x)
8483
if type(x) == 'table' then
8584
print("test10 in script 3 is a table:")
@@ -90,9 +89,9 @@ for i=1,50 do
9089
end
9190
end
9291

93-
print("END",LuaStepper.taskStatus(0))
94-
print("END",LuaStepper.taskStatus(1))
95-
print("END",LuaStepper.taskStatus(4))
96-
LuaStepper.closeTask(0)
97-
LuaStepper.closeTask(1)
98-
LuaStepper.closeTask(4)
92+
print("END",lStepper.taskStatus(0))
93+
print("END",lStepper.taskStatus(1))
94+
print("END",lStepper.taskStatus(4))
95+
lStepper.closeTask(0)
96+
lStepper.closeTask(1)
97+
lStepper.closeTask(4)

0 commit comments

Comments
 (0)