Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Added hook system. Began work on experimental overarching thread syst…
…em. Added unpack method to see.base.Array for converting to varargs.
- Loading branch information
James King
committed
Aug 10, 2013
1 parent
de68e1f
commit 4c35829
Showing
10 changed files
with
175 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function Hook:init(id, event, callback) | ||
| self.id = id | ||
| self.event = event | ||
| self.callback = callback | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --@native os.pullEvent | ||
| --@native unpack | ||
|
|
||
| --@import see.hook.Hook | ||
| --@import see.concurrent.Thread | ||
|
|
||
| local hooks = { } | ||
| local running | ||
|
|
||
| function Hooks.run() | ||
| local eventData = Array.new(os.pullEvent()) | ||
| if eventData:length() == 0 then | ||
| return | ||
| end | ||
| local event = eventData[1] | ||
| eventData:remove(1) | ||
| if hooks[event] then | ||
| for hook in hooks[event]:iAll() do | ||
| hook.callback(eventData:unpack()) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function Hooks.add(event, callback) | ||
| local t = hooks[event] | ||
| if not t then | ||
| t = Array.new() | ||
| hooks[event] = t | ||
| end | ||
| local hook = Hook.new(#t + 1, event, callback) | ||
| t:add(hook) | ||
| return hook | ||
| end | ||
|
|
||
| function Hooks.remove(hook) | ||
| hooks[hook.event]:remove(hook.id) | ||
| hook.id = -1 | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --@import see.hook.Hooks | ||
|
|
||
| function Test.main() | ||
| local hook | ||
| local input = true | ||
| local str = String.new() | ||
| hook = Hooks.add("char", function(c) | ||
| if c == "z" then | ||
| input = false | ||
| Hooks.remove(hook) | ||
| else | ||
| str:add(c) | ||
| end | ||
| end) | ||
|
|
||
| while input do | ||
| Hooks.run() | ||
| end | ||
|
|
||
| System.print(str) | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| shell.run("/see/programs/see", "-r", "/see/", "/see/test/", "see.example.Test", "Yevano") | ||
| shell.run("/see/programs/see", "-r", "/see/", "/see/test/", "see.dev.Test", "") |