Fixed issue with threaded functions and how they interact with the threaded enviroment
This commit is contained in:
parent
6dbf2f5e93
commit
aaff2244b1
28
changes.md
28
changes.md
@ -3,6 +3,34 @@
|
|||||||
Update 14.1.0 Bug Fixes and a change
|
Update 14.1.0 Bug Fixes and a change
|
||||||
-------------
|
-------------
|
||||||
# Added:
|
# Added:
|
||||||
|
- thread enviroments are able to interact with threaded functions and wait when there is the presence of variables. Only works when creating "Globals" inside of a thread. The way the enviroment has been set up is that it sets your "Global" as a "GLocal" a global variable local to the threaded enviroment. This does not have the access speed benifits that using pure locals have..
|
||||||
|
```lua
|
||||||
|
package.path="?/init.lua;?.lua;"..package.path
|
||||||
|
multi,thread = require("multi"):init()
|
||||||
|
a,b = 6,7
|
||||||
|
multi:newThread(function()
|
||||||
|
function test() -- Auto converts your function into a threaded function
|
||||||
|
thread.sleep(1)
|
||||||
|
return 1,2
|
||||||
|
end
|
||||||
|
a,b = test().wait() -- Will modify Global
|
||||||
|
-- when wait is used the special metamethod routine is not triggered and variables are set as normal
|
||||||
|
a,b = test() -- Will modify GLocal
|
||||||
|
-- the threaded function test triggers a special routine within the metamethod that alters the thread's enviroment instead of the global enviroment.
|
||||||
|
print("Waited:",a,b)
|
||||||
|
--This returns instantly even though the function isn't done!
|
||||||
|
test().connect(function(a,b)
|
||||||
|
print("Connected:",a,b)
|
||||||
|
os.exit()
|
||||||
|
end)
|
||||||
|
-- This waits for the returns since we are demanding them
|
||||||
|
end)
|
||||||
|
multi:newAlarm(2):OnRing(function()
|
||||||
|
print(a,b)
|
||||||
|
end)
|
||||||
|
--min,hour,day,wday,month
|
||||||
|
multi:mainloop()
|
||||||
|
```
|
||||||
- multi:scheduleJob(time,func)
|
- multi:scheduleJob(time,func)
|
||||||
- time.min -- Minute a value of (0-59)
|
- time.min -- Minute a value of (0-59)
|
||||||
- time.hour -- Hour a value of (0-23)
|
- time.hour -- Hour a value of (0-23)
|
||||||
|
|||||||
@ -1559,10 +1559,10 @@ function multi:newThread(name,func,...)
|
|||||||
table.insert(s,e)
|
table.insert(s,e)
|
||||||
table.insert(s,f)
|
table.insert(s,f)
|
||||||
local x = table.remove(_G["_stack_"])
|
local x = table.remove(_G["_stack_"])
|
||||||
Gref[k]=x
|
rawset(t,k,x)
|
||||||
else
|
else
|
||||||
local x = table.remove(_G["_stack_"])
|
local x = table.remove(_G["_stack_"])
|
||||||
Gref[k]=x
|
rawset(t,k,x)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Gref[k]=v
|
Gref[k]=v
|
||||||
|
|||||||
10
test.lua
10
test.lua
@ -1,18 +1,22 @@
|
|||||||
package.path="?/init.lua;?.lua;"..package.path
|
package.path="?/init.lua;?.lua;"..package.path
|
||||||
multi,thread = require("multi"):init()
|
multi,thread = require("multi"):init()
|
||||||
|
a,b = 6,7
|
||||||
multi:newThread(function()
|
multi:newThread(function()
|
||||||
function test()
|
function test()
|
||||||
thread.sleep(1)
|
thread.sleep(1)
|
||||||
return 1,2
|
return 1,2
|
||||||
end
|
end
|
||||||
|
a,b = test().wait()
|
||||||
|
print("Waited:",a,b)
|
||||||
--This returns instantly even though the function isn't done!
|
--This returns instantly even though the function isn't done!
|
||||||
test().connect(function(a,b)
|
test().connect(function(a,b)
|
||||||
print("Connected:",a,b)
|
print("Connected:",a,b)
|
||||||
|
os.exit()
|
||||||
end)
|
end)
|
||||||
-- This waits for the returns since we are demanding them
|
-- This waits for the returns since we are demanding them
|
||||||
a,b = test()
|
end)
|
||||||
print("Waited:",a,b)
|
multi:newAlarm(2):OnRing(function()
|
||||||
os.exit()
|
print(a,b)
|
||||||
end)
|
end)
|
||||||
--min,hour,day,wday,month
|
--min,hour,day,wday,month
|
||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user