diff options
author | Alexey Melnichuk <mimir@newmail.ru> | 2014-01-09 12:59:35 +0400 |
---|---|---|
committer | Alexey Melnichuk <mimir@newmail.ru> | 2014-01-09 12:59:35 +0400 |
commit | f7b4f850de76533f91584bc7578ff12f6a8b5c70 (patch) | |
tree | 256aba2d860b4cbb2a7da54816c97e77fbebb9f8 | |
parent | f259a7328461722cd3ff27c27dfbc30ffd48e96f (diff) | |
download | lua-llthreads2-f7b4f850de76533f91584bc7578ff12f6a8b5c70.tar.gz lua-llthreads2-f7b4f850de76533f91584bc7578ff12f6a8b5c70.tar.bz2 lua-llthreads2-f7b4f850de76533f91584bc7578ff12f6a8b5c70.zip |
Add. library version
-rw-r--r-- | src/llthread.c | 45 | ||||
-rw-r--r-- | test/test_llthreads.lua | 2 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/llthread.c b/src/llthread.c index 88d3805..27253e5 100644 --- a/src/llthread.c +++ b/src/llthread.c | |||
@@ -2,6 +2,11 @@ | |||
2 | # define USE_PTHREAD | 2 | # define USE_PTHREAD |
3 | #endif | 3 | #endif |
4 | 4 | ||
5 | #define LLTHREAD_VERSION_MAJOR 0 | ||
6 | #define LLTHREAD_VERSION_MINOR 1 | ||
7 | #define LLTHREAD_VERSION_PATCH 0 | ||
8 | #define LLTHREAD_VERSION_COMMENT "dev" | ||
9 | |||
5 | #ifndef USE_PTHREAD | 10 | #ifndef USE_PTHREAD |
6 | # include <windows.h> | 11 | # include <windows.h> |
7 | # include <process.h> | 12 | # include <process.h> |
@@ -607,6 +612,40 @@ static const struct luaL_Reg l_llthread_meth[] = { | |||
607 | 612 | ||
608 | //} | 613 | //} |
609 | 614 | ||
615 | //{ version | ||
616 | |||
617 | static int l_llthread_version(lua_State *L){ | ||
618 | lua_pushnumber(L, LLTHREAD_VERSION_MAJOR); | ||
619 | lua_pushnumber(L, LLTHREAD_VERSION_MINOR); | ||
620 | lua_pushnumber(L, LLTHREAD_VERSION_PATCH); | ||
621 | #ifdef LLTHREAD_VERSION_COMMENT | ||
622 | if(LLTHREAD_VERSION_COMMENT[0]){ | ||
623 | lua_pushliteral(L, LLTHREAD_VERSION_COMMENT); | ||
624 | return 4; | ||
625 | } | ||
626 | #endif | ||
627 | return 3; | ||
628 | } | ||
629 | |||
630 | static int l_llthread_push_version(lua_State *L){ | ||
631 | lua_pushnumber(L, LLTHREAD_VERSION_MAJOR); | ||
632 | lua_pushliteral(L, "."); | ||
633 | lua_pushnumber(L, LLTHREAD_VERSION_MINOR); | ||
634 | lua_pushliteral(L, "."); | ||
635 | lua_pushnumber(L, LLTHREAD_VERSION_PATCH); | ||
636 | #ifdef LLTHREAD_VERSION_COMMENT | ||
637 | if(LLTHREAD_VERSION_COMMENT[0]){ | ||
638 | lua_pushliteral(L, "-"LLTHREAD_VERSION_COMMENT); | ||
639 | lua_concat(L, 6); | ||
640 | } | ||
641 | else | ||
642 | #endif | ||
643 | lua_concat(L, 5); | ||
644 | return 1; | ||
645 | } | ||
646 | |||
647 | //} | ||
648 | |||
610 | static int l_llthread_set_logger(lua_State *L){ | 649 | static int l_llthread_set_logger(lua_State *L){ |
611 | lua_settop(L, 1); | 650 | lua_settop(L, 1); |
612 | luaL_argcheck(L, lua_isfunction(L, 1), 1, "function expected"); | 651 | luaL_argcheck(L, lua_isfunction(L, 1), 1, "function expected"); |
@@ -617,6 +656,7 @@ static int l_llthread_set_logger(lua_State *L){ | |||
617 | static const struct luaL_Reg l_llthreads_lib[] = { | 656 | static const struct luaL_Reg l_llthreads_lib[] = { |
618 | {"new", l_llthread_new }, | 657 | {"new", l_llthread_new }, |
619 | {"set_logger", l_llthread_set_logger }, | 658 | {"set_logger", l_llthread_set_logger }, |
659 | {"version", l_llthread_version }, | ||
620 | 660 | ||
621 | {NULL, NULL} | 661 | {NULL, NULL} |
622 | }; | 662 | }; |
@@ -628,5 +668,10 @@ LLTHREADS_EXPORT_API int LLTHREAD_OPEN_NAME(lua_State *L) { | |||
628 | 668 | ||
629 | lua_newtable(L); | 669 | lua_newtable(L); |
630 | luaL_setfuncs(L, l_llthreads_lib, 0); | 670 | luaL_setfuncs(L, l_llthreads_lib, 0); |
671 | |||
672 | lua_pushliteral(L, "_VERSION"); | ||
673 | l_llthread_push_version(L); | ||
674 | lua_rawset(L, -3); | ||
675 | |||
631 | return 1; | 676 | return 1; |
632 | } | 677 | } |
diff --git a/test/test_llthreads.lua b/test/test_llthreads.lua index df8c6a2..e0e214b 100644 --- a/test/test_llthreads.lua +++ b/test/test_llthreads.lua | |||
@@ -21,6 +21,8 @@ | |||
21 | local llthreads = require"llthreads" | 21 | local llthreads = require"llthreads" |
22 | local sleep = require"utils".sleep | 22 | local sleep = require"utils".sleep |
23 | 23 | ||
24 | print("LLThreads version : ", llthreads._VERSION) | ||
25 | |||
24 | local function detached_thread(...) | 26 | local function detached_thread(...) |
25 | local thread = llthreads.new([[ print("print_detached_thread:", ...) ]], ...) | 27 | local thread = llthreads.new([[ print("print_detached_thread:", ...) ]], ...) |
26 | -- start detached thread | 28 | -- start detached thread |