aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/llthread.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/llthread.c b/src/llthread.c
index 0c4a107..88d3805 100644
--- a/src/llthread.c
+++ b/src/llthread.c
@@ -80,11 +80,21 @@ typedef pthread_t os_thread_t;
80#define ALLOC_STRUCT(S) (S*)calloc(1, sizeof(S)) 80#define ALLOC_STRUCT(S) (S*)calloc(1, sizeof(S))
81#define FREE_STRUCT(O) free(O) 81#define FREE_STRUCT(O) free(O)
82 82
83LLTHREADS_EXPORT_API int luaopen_llthreads(lua_State *L); 83#ifndef LLTHREAD_MODULE_NAME
84# define LLTHREAD_MODULE_NAME llthreads
85#endif
86
87#define CAT(S1,S2) S1##S2
88
89#define LLTHREAD_OPEN_NAME_IMPL(NAME) CAT(luaopen_, NAME)
90
91#define LLTHREAD_OPEN_NAME LLTHREAD_OPEN_NAME_IMPL(LLTHREAD_MODULE_NAME)
92
93LLTHREADS_EXPORT_API int LLTHREAD_OPEN_NAME(lua_State *L);
84 94
85#define LLTHREAD_T_NAME "LLThread" 95#define LLTHREAD_NAME "LLThread"
86static const char *LLTHREAD_T = LLTHREAD_T_NAME; 96static const char *LLTHREAD_TAG = LLTHREAD_NAME;
87static const char *LLTHREAD_LOGGER_HOLDER = LLTHREAD_T_NAME " logger holder"; 97static const char *LLTHREAD_LOGGER_HOLDER = LLTHREAD_NAME " logger holder";
88 98
89typedef struct llthread_child_t { 99typedef struct llthread_child_t {
90 lua_State *L; 100 lua_State *L;
@@ -476,7 +486,7 @@ static llthread_t *llthread_create(lua_State *L, const char *code, size_t code_l
476//{ Lua interface to llthread 486//{ Lua interface to llthread
477 487
478static llthread_t *l_llthread_at (lua_State *L, int i) { 488static llthread_t *l_llthread_at (lua_State *L, int i) {
479 llthread_t **this = (llthread_t **)lutil_checkudatap (L, i, LLTHREAD_T); 489 llthread_t **this = (llthread_t **)lutil_checkudatap (L, i, LLTHREAD_TAG);
480 luaL_argcheck (L, this != NULL, i, "thread expected"); 490 luaL_argcheck (L, this != NULL, i, "thread expected");
481 luaL_argcheck (L, *this != NULL, i, "thread expected"); 491 luaL_argcheck (L, *this != NULL, i, "thread expected");
482 // luaL_argcheck (L, !(counter->flags & FLAG_DESTROYED), 1, "PDH Counter is destroyed"); 492 // luaL_argcheck (L, !(counter->flags & FLAG_DESTROYED), 1, "PDH Counter is destroyed");
@@ -484,7 +494,7 @@ static llthread_t *l_llthread_at (lua_State *L, int i) {
484} 494}
485 495
486static int l_llthread_delete(lua_State *L) { 496static int l_llthread_delete(lua_State *L) {
487 llthread_t **pthis = (llthread_t **)lutil_checkudatap (L, 1, LLTHREAD_T); 497 llthread_t **pthis = (llthread_t **)lutil_checkudatap (L, 1, LLTHREAD_TAG);
488 luaL_argcheck (L, pthis != NULL, 1, "thread expected"); 498 luaL_argcheck (L, pthis != NULL, 1, "thread expected");
489 if(*pthis == NULL) return 0; 499 if(*pthis == NULL) return 0;
490 llthread_destroy(*pthis); 500 llthread_destroy(*pthis);
@@ -579,7 +589,7 @@ static int l_llthread_join(lua_State *L) {
579 589
580static int l_llthread_new(lua_State *L) { 590static int l_llthread_new(lua_State *L) {
581 size_t lua_code_len; const char *lua_code = luaL_checklstring(L, 1, &lua_code_len); 591 size_t lua_code_len; const char *lua_code = luaL_checklstring(L, 1, &lua_code_len);
582 llthread_t **this = lutil_newudatap(L, llthread_t*, LLTHREAD_T); 592 llthread_t **this = lutil_newudatap(L, llthread_t*, LLTHREAD_TAG);
583 lua_insert(L, 2); /*move self prior args*/ 593 lua_insert(L, 2); /*move self prior args*/
584 *this = llthread_create(L, lua_code, lua_code_len); 594 *this = llthread_create(L, lua_code, lua_code_len);
585 595
@@ -611,9 +621,9 @@ static const struct luaL_Reg l_llthreads_lib[] = {
611 {NULL, NULL} 621 {NULL, NULL}
612}; 622};
613 623
614LLTHREADS_EXPORT_API int luaopen_llthreads(lua_State *L) { 624LLTHREADS_EXPORT_API int LLTHREAD_OPEN_NAME(lua_State *L) {
615 int top = lua_gettop(L); 625 int top = lua_gettop(L);
616 lutil_createmetap(L, LLTHREAD_T, l_llthread_meth, 0); 626 lutil_createmetap(L, LLTHREAD_TAG, l_llthread_meth, 0);
617 lua_settop(L, top); 627 lua_settop(L, top);
618 628
619 lua_newtable(L); 629 lua_newtable(L);