bakpakin / corope Goto Github PK
View Code? Open in Web Editor NEWLua threading utility using coroutines.
License: MIT License
Lua threading utility using coroutines.
License: MIT License
I can't seem to get the rope:parallel function to work. Everything I've tried results in the following error:
Error: corope.lua:328: rope function called outside of dispatch function or inside coroutine
stack traceback:
[C]: in function 'error'
tests/utils/corope.lua:157: in function 'checkCorrectCoroutine'
tests/utils/corope.lua:296: in function 'signal'
tests/utils/corope.lua:328: in function 'errhand'
tests/utils/corope.lua:106: in function 'update'
tests/coropetest.lua:6: in function 'update'
[string "boot.lua"]:464: in function <[string "boot.lua"]:436>
[C]: in function 'xpcall'
My simple function call for testing looks like this:
bundle(function(rope)
rope:parallel(
function()
print "First"
rope:wait(0.5)
end,
function()
print "Second"
rope:wait(1.5)
end
)
print "Last"
end)
Going by the documentation, I would expect it to output:
First
Second
Last
Instead it throws the error message shown above.
Would it be possible to get an example showing how the Parallel function is meant to be used?
thank you very much for your library. I want to implement it in it. could you tell me, please, how to do this?
I try to implement multithreading in Lua Api through coroutines using lua_sethook.
here's the code
void LUAHook(lua_State* L, lua_Debug* ar) {
lua_yield(L, 0);
};
const char* LUA = R"(
function foo()
for i = 1, 4 do
print(" func foo \n")
end end
function main()
for i = 1, 3 do
print(" func main "..i.."\n")
if j == nil
then
foo1()
j=1
end
end end
)";
int foo1(lua_State* L) {
lua_State* L1 = lua_newthread(L);
lua_sethook(L, LUAHook, LUA_MASKLINE, 1);
lua_getglobal(L1, "foo");
lua_sethook(L1, LUAHook, LUA_MASKLINE, 1);
lua_resume(L1, L, 0);
return 0;
};
int main() {
lua_State* L = luaL_newstate(); luaL_openlibs(L);
lua_register(L, "foo1", foo1);
luaL_dostring(L, LUA);
int ret;
lua_getglobal(L, "main");// функция lua возобновляется с последней
// прерванной позиции.
ret = lua_resume(L, NULL, 0);
return 0;
};
me need to display the following in the console
func main 1
func foo
func main 2
func foo
func main 3
func foo
Whenever I do a call to rope:listen, the thread crashes because the table index is nil. Specifically, it errors on the line ts[index] = ts[#ts]
on line 73. I can't find index
defined anywhere, so I'm not sure what was meant here.
Example of the code I'm using:
bundle(function(rope)
-- do something
rope:listen("keypress") -- crashes here
-- do more stuff
end)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.