diff options
author | Diego Nehab <diego.nehab@gmail.com> | 2015-08-21 15:39:34 -0300 |
---|---|---|
committer | Diego Nehab <diego.nehab@gmail.com> | 2015-08-21 15:39:34 -0300 |
commit | e75444ccd1f30a3b5fbc7cec4a85e831bd0560ed (patch) | |
tree | 71475c18fee070c770fc0fe25d0859b7d54c8fbb /src/timeout.c | |
parent | 321c0c9b1f7b6b83cd83b58e7e259f53eca69373 (diff) | |
download | luasocket-e75444ccd1f30a3b5fbc7cec4a85e831bd0560ed.tar.gz luasocket-e75444ccd1f30a3b5fbc7cec4a85e831bd0560ed.tar.bz2 luasocket-e75444ccd1f30a3b5fbc7cec4a85e831bd0560ed.zip |
New compat.h module implements luaL_setfuncs.
Makes initialization code simpler everywhere.
Diffstat (limited to 'src/timeout.c')
-rw-r--r-- | src/timeout.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/timeout.c b/src/timeout.c index bdd5e1c..087d033 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
@@ -8,6 +8,7 @@ | |||
8 | 8 | ||
9 | #include "lua.h" | 9 | #include "lua.h" |
10 | #include "lauxlib.h" | 10 | #include "lauxlib.h" |
11 | #include "compat.h" | ||
11 | 12 | ||
12 | #include "auxiliar.h" | 13 | #include "auxiliar.h" |
13 | #include "timeout.h" | 14 | #include "timeout.h" |
@@ -52,7 +53,7 @@ void timeout_init(p_timeout tm, double block, double total) { | |||
52 | 53 | ||
53 | /*-------------------------------------------------------------------------*\ | 54 | /*-------------------------------------------------------------------------*\ |
54 | * Determines how much time we have left for the next system call, | 55 | * Determines how much time we have left for the next system call, |
55 | * if the previous call was successful | 56 | * if the previous call was successful |
56 | * Input | 57 | * Input |
57 | * tm: timeout control structure | 58 | * tm: timeout control structure |
58 | * Returns | 59 | * Returns |
@@ -107,7 +108,7 @@ double timeout_getretry(p_timeout tm) { | |||
107 | } | 108 | } |
108 | 109 | ||
109 | /*-------------------------------------------------------------------------*\ | 110 | /*-------------------------------------------------------------------------*\ |
110 | * Marks the operation start time in structure | 111 | * Marks the operation start time in structure |
111 | * Input | 112 | * Input |
112 | * tm: timeout control structure | 113 | * tm: timeout control structure |
113 | \*-------------------------------------------------------------------------*/ | 114 | \*-------------------------------------------------------------------------*/ |
@@ -117,7 +118,7 @@ p_timeout timeout_markstart(p_timeout tm) { | |||
117 | } | 118 | } |
118 | 119 | ||
119 | /*-------------------------------------------------------------------------*\ | 120 | /*-------------------------------------------------------------------------*\ |
120 | * Gets time in s, relative to January 1, 1970 (UTC) | 121 | * Gets time in s, relative to January 1, 1970 (UTC) |
121 | * Returns | 122 | * Returns |
122 | * time in s. | 123 | * time in s. |
123 | \*-------------------------------------------------------------------------*/ | 124 | \*-------------------------------------------------------------------------*/ |
@@ -144,11 +145,7 @@ double timeout_gettime(void) { | |||
144 | * Initializes module | 145 | * Initializes module |
145 | \*-------------------------------------------------------------------------*/ | 146 | \*-------------------------------------------------------------------------*/ |
146 | int timeout_open(lua_State *L) { | 147 | int timeout_open(lua_State *L) { |
147 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) | ||
148 | luaL_setfuncs(L, func, 0); | 148 | luaL_setfuncs(L, func, 0); |
149 | #else | ||
150 | luaL_openlib(L, NULL, func, 0); | ||
151 | #endif | ||
152 | return 0; | 149 | return 0; |
153 | } | 150 | } |
154 | 151 | ||
@@ -163,7 +160,7 @@ int timeout_meth_settimeout(lua_State *L, p_timeout tm) { | |||
163 | const char *mode = luaL_optstring(L, 3, "b"); | 160 | const char *mode = luaL_optstring(L, 3, "b"); |
164 | switch (*mode) { | 161 | switch (*mode) { |
165 | case 'b': | 162 | case 'b': |
166 | tm->block = t; | 163 | tm->block = t; |
167 | break; | 164 | break; |
168 | case 'r': case 't': | 165 | case 'r': case 't': |
169 | tm->total = t; | 166 | tm->total = t; |