From 161ec7edd08ab4f0ffffefa81c75e37c1a89ecd2 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Mon, 23 Jun 2014 11:20:46 +0500 Subject: Update doc --- src/lua/llthreads2/ex.lua | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/lua/llthreads2/ex.lua b/src/lua/llthreads2/ex.lua index 26e1a46..bd8888d 100644 --- a/src/lua/llthreads2/ex.lua +++ b/src/lua/llthreads2/ex.lua @@ -1,6 +1,6 @@ +--- Wraps the low-level threads object. -- --- wraps the low-level threads object. --- +-- @module llthreads2.ex -- -- Note! Define this function prior all `local` definitions @@ -95,16 +95,30 @@ end local thread_mt = {} do thread_mt.__index = thread_mt +--- Thread object. +-- +-- @type thread + +--- Start thread. +-- +-- @tparam ?boolean detached +-- @tparam ?boolean joinable +-- @return self function thread_mt:start(...) local ok, err = self.thread:start(...) if not ok then return nil, err end return self end +--- Join thread. +-- +-- @tparam ?number timeout Windows suppurts arbitrary value, but POSIX supports only 0 function thread_mt:join(...) return self.thread:join(...) end +--- Check if thread still working. +-- You can call `join` to get returned values if thiread is not alive. function thread_mt:alive() return self.thread:alive() end @@ -115,7 +129,7 @@ end ------------------------------------------------------------------------------- local threads = {} do -local function new_thread(prelude, lua_init, code, ...) +local function new_thread(lua_init, prelude, code, ...) if type(lua_init) == "function" then lua_init = string.dump(lua_init) end @@ -134,19 +148,33 @@ local function new_thread(prelude, lua_init, code, ...) }, thread_mt) end +--- Create new thread object +-- +-- @tparam string|function|THREAD_OPTIONS source thread source code. +-- threads.new = function (code, ...) assert(code) if type(code) == "table" then local source = assert(code.source or code[1]) local init = (code.lua_init == nil) and LUA_INIT or code.lua_init - return new_thread(code.prelude, init, source, ...) + return new_thread(init, code.prelude, source, ...) end - return new_thread(nil, LUA_INIT, code, ...) + return new_thread(LUA_INIT, nil, code, ...) end end ------------------------------------------------------------------------------- +--- A table describe threads constructor options. +-- +-- @tfield string|function source thread source code (or first value of table) +-- @tfield ?string|function prelude thread prelude code. This code can change thread arguments. +-- e.g. it can remove some values or change their type. +-- @lua_init ?string|function|false by default child lua state try use LUA_INIT environment variable +-- just like regular lua interpretator. +-- +-- @table THREAD_OPTIONS + return threads \ No newline at end of file -- cgit v1.2.3-55-g6feb