aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoteus <mimir@newmail.ru>2013-12-27 18:25:00 +0400
committermoteus <mimir@newmail.ru>2013-12-27 18:25:00 +0400
commita087c2737441aad781be7e3d88775e688152ad4e (patch)
tree582a8dd895f13eed50ff727c4fc75d5b9b48be9b
parenta26ecf383900e4c396958da80200cb2eb1121506 (diff)
downloadlua-llthreads2-a087c2737441aad781be7e3d88775e688152ad4e.tar.gz
lua-llthreads2-a087c2737441aad781be7e3d88775e688152ad4e.tar.bz2
lua-llthreads2-a087c2737441aad781be7e3d88775e688152ad4e.zip
Add. pass cfunctions to child thread.
-rw-r--r--.travis.yml1
-rw-r--r--README.md2
-rw-r--r--src/llthread.c5
-rw-r--r--test/test_pass_cfunction.lua17
4 files changed, 24 insertions, 1 deletions
diff --git a/.travis.yml b/.travis.yml
index 7cadb6a..d02d26a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -52,6 +52,7 @@ script:
52 - lua$LUA_SFX test_join_detach.lua 52 - lua$LUA_SFX test_join_detach.lua
53 - lua$LUA_SFX test_register_ffi.lua 53 - lua$LUA_SFX test_register_ffi.lua
54 - lua$LUA_SFX test_logger.lua 54 - lua$LUA_SFX test_logger.lua
55 - lua$LUA_SFX test_pass_cfunction.lua
55 56
56notifications: 57notifications:
57 email: 58 email:
diff --git a/README.md b/README.md
index d384055..b18459e 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,6 @@ This is full dropin replacement for [llthreads](https://github.com/Neopallium/lu
9* does not support ffi interface (use Lua C API for LuaJIT) 9* does not support ffi interface (use Lua C API for LuaJIT)
10* returns nil instead of false on error 10* returns nil instead of false on error
11* start method returns self instead of true on success 11* start method returns self instead of true on success
12* does not open all standart libraries (set LLTHREAD_REGISTER_STD_LIBRARY to on this feature)
13* register loaders for llthreads library itself 12* register loaders for llthreads library itself
14 13
15##Additional 14##Additional
@@ -17,6 +16,7 @@ This is full dropin replacement for [llthreads](https://github.com/Neopallium/lu
17* thread:join() method support arbitrary timeout on Windows threads 16* thread:join() method support arbitrary timeout on Windows threads
18* set_logger function allow logging errors (crash Lua VM) in current llthread's threads 17* set_logger function allow logging errors (crash Lua VM) in current llthread's threads
19* thread:start() has additional parameter which control in which thread child Lua VM will be destroyed 18* thread:start() has additional parameter which control in which thread child Lua VM will be destroyed
19* allow pass cfunctions to child thread (e.g. to initialize Lua state) (experemental)
20 20
21##Usage 21##Usage
22 22
diff --git a/src/llthread.c b/src/llthread.c
index 668a8c8..88498a8 100644
--- a/src/llthread.c
+++ b/src/llthread.c
@@ -228,6 +228,11 @@ static int llthread_copy_value(llthread_copy_state *state, int depth, int idx) {
228 } 228 }
229 break; 229 break;
230 case LUA_TFUNCTION: 230 case LUA_TFUNCTION:
231 if(lua_iscfunction(state->from_L, idx)){
232 lua_CFunction fn = lua_tocfunction(state->from_L, idx);
233 lua_pushcfunction(state->to_L, fn);
234 break;
235 }
231 case LUA_TUSERDATA: 236 case LUA_TUSERDATA:
232 case LUA_TTHREAD: 237 case LUA_TTHREAD:
233 default: 238 default:
diff --git a/test/test_pass_cfunction.lua b/test/test_pass_cfunction.lua
new file mode 100644
index 0000000..86fcd3d
--- /dev/null
+++ b/test/test_pass_cfunction.lua
@@ -0,0 +1,17 @@
1local llthreads = require"llthreads"
2local utils = require"utils"
3
4local thread = llthreads.new(utils.thread_init .. [[
5 require "llthreads"
6 local fn = ...
7
8 if type(fn) ~= 'function' then
9 print("ERROR! No function : ", fn, type(fn))
10 os.exit(-2)
11 end
12
13 fn("print('Done!'); require'os'.exit(0)"):start():join()
14]], llthreads.new)
15
16print(thread:start():join())
17os.exit(-1) \ No newline at end of file