diff options
author | Felix Fietkau <nbd@openwrt.org> | 2012-09-27 15:47:46 +0400 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2012-09-27 15:47:46 +0400 |
commit | 0a81131257609b63040e8ccedbc65223da893d79 (patch) | |
tree | cbe4d0aa6cbaaf558a574e03062b55ebdd0890df /examples | |
parent | a81cb397efa3fd705d0989d992b677e57f237413 (diff) |
add an example script for the uloop lua binding
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/uloop-example.lua | 44 | ||||
-rwxr-xr-x | examples/uloop_pid_test.sh | 11 |
2 files changed, 55 insertions, 0 deletions
diff --git a/examples/uloop-example.lua b/examples/uloop-example.lua new file mode 100755 index 0000000..2da6ebd --- /dev/null +++ b/examples/uloop-example.lua @@ -0,0 +1,44 @@ +#!/usr/bin/env lua + +local uloop = require("uloop") +uloop.init() + +-- timer example 1 +local timer +function t() + print("1000 ms timer run"); + timer:set(1000) +end +timer = uloop.timer(t) +timer:set(1000) + +-- timer example 2 +uloop.timer(function() print("2000 ms timer run"); end, 2000) + +-- timer example 3 +uloop.timer(function() print("3000 ms timer run"); end, 3000):cancel() + +-- process +function p1(r) + print("Process 1 completed") + print(r) +end + +function p2(r) + print("Process 2 completed") + print(r) +end + +uloop.timer( + function() + uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=1"}, p1) + end, 1000 +) +uloop.timer( + function() + uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=2"}, p2) + end, 2000 +) + +uloop.run() + diff --git a/examples/uloop_pid_test.sh b/examples/uloop_pid_test.sh new file mode 100755 index 0000000..c622064 --- /dev/null +++ b/examples/uloop_pid_test.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +echo $0 $* +echo Environment: +env + +sleep 2 + +echo "stopping child" + +exit 5 |