Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug #105

Open
ka7713 opened this issue Jun 26, 2018 · 4 comments
Open

bug #105

ka7713 opened this issue Jun 26, 2018 · 4 comments

Comments

@ka7713
Copy link

ka7713 commented Jun 26, 2018

A bug occurs when adding from inside a loop.

signal.register(AAA, function()
....
signal.register(AAA, ...)
....
end)
signal.emit(AAA)

timer.after(1.0, function()
...
timer.after(1.0, ...)
...
end)

@vrld
Copy link
Owner

vrld commented Jun 26, 2018

What is the error message?

@vrld
Copy link
Owner

vrld commented Jun 26, 2018

Can you please give more information? What did you expect and what did you get instead? Your example ...

signal.register("slot", function()
  print("Foo")
  signal.register("slot", function() print("Bar") end)
  print("Baz")
end)

signal.emit("slot")

... Works as expected:

Foo
Baz
Bar

The timer example also works as expected:

timer.after(1, function()
  print("Foo")
  timer.after(1, function()
    print("Bar")
  end)
end)

timer.update(1) --> Foo
timer.update(1) --> Bar

@ka7713
Copy link
Author

ka7713 commented Jun 27, 2018

signal = require("signal")

function register()
	signal.register(1, function()
	  print("Foo")
	  signal.register(1, function() print("Bar") end)
	  print("Baz")
	end)
end

for i=1, 10 do
	register()
	signal.emit(1)
	signal.clear(1)
	print("---")
end

(LuaJIT 2.0.5)

luajit.exe test.lua
Foo
Baz -- <<--- I think this is right. Because Bar is register after emit.
---
Foo
Baz
---
Foo
Baz
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---

(lua 5.1.4)

lua5.1.exe test.lua
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---

(I'm sorry, My English is not good)

@ka7713
Copy link
Author

ka7713 commented Jun 27, 2018

more sample

signal = require("signal")

function test1(mode)
	print("Foo")
	signal.register(1, function() print("Bar") end)
	print("Baz")
end

function register()
	signal.register(1, test1)
	signal.register(1, function() end)
	signal.register(1, function() end)
	signal.register(1, function() end)
end

for i=1,10 do
	register()
	signal.emit(1)
	signal.clear(1)
	print("---")
end
luajit.exe test.lua
Foo
Baz
Bar
Foo --<< call twice
Baz
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Bar
Foo
Baz
---
Foo
Baz
Bar
Foo
Baz
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Bar
Foo
Baz
---
lua5.1.exe test.lua
Foo
Baz
Bar
---
Foo --<<
Baz
---
Foo --<<
Baz
---
Foo
Baz
Bar
---
Foo --<<
Baz
---
Foo
Baz
Bar
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo --<<
Baz
---

Timer

timer = require("timer")

function register()
	timer.after(0.5, function() 
		print("Foo")
		-- Bar total 1 second
		timer.after(0.5, function() print("Bar") end)
		print("Baz")
	end)
	timer.after(0.5, function() end)
	timer.after(0.5, function() end)
	timer.after(0.5, function() end)
end

for i=1,10 do
	register()
	timer.update(0.5)
	timer.clear()
	print("---")
end
luajit.exe test3.lua
Foo
Baz
Bar -- Bar 1 sec but call 0.5 sec
---
Foo
Baz
Bar
---
Foo
Baz
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
lua5.1.exe test3.lua
Foo
Baz
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants