Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Lua integer in thread and async arguments #727

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lthreadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ typedef struct {
int type;
union
{
lua_Number num;
struct {
int isinteger;
union {
lua_Number n;
lua_Integer i;
} value;
} num;
int boolean;
struct {
const char* base;
Expand Down
13 changes: 11 additions & 2 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ static int luv_thread_arg_set(lua_State* L, luv_thread_arg_t* args, int idx, int
arg->val.boolean = lua_toboolean(L, i);
break;
case LUA_TNUMBER:
arg->val.num = lua_tonumber(L, i);
arg->val.num.isinteger = lua_isinteger(L, i);
if (arg->val.num.isinteger) {
arg->val.num.value.i = lua_tointeger(L, i);
} else {
arg->val.num.value.n = lua_tonumber(L, i);
}
break;
case LUA_TSTRING:
if (async)
Expand Down Expand Up @@ -181,7 +186,11 @@ static int luv_thread_arg_push(lua_State* L, luv_thread_arg_t* args, int flags)
lua_pushboolean(L, arg->val.boolean);
break;
case LUA_TNUMBER:
lua_pushnumber(L, arg->val.num);
if (arg->val.num.isinteger) {
lua_pushinteger(L, arg->val.num.value.i);
} else {
lua_pushnumber(L, arg->val.num.value.n);
}
break;
case LUA_TSTRING:
lua_pushlstring(L, arg->val.str.base, arg->val.str.len);
Expand Down
6 changes: 4 additions & 2 deletions tests/test-thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ return require('lib/tap')(function (test)
local delay = 100
uv.update_time()
local before = uv.now()
local args = {delay, 'string', nil, false, 5, "helloworld"}
local args = {delay, 'string', nil, false, 5, 3.14, "helloworld"}
local unpack = unpack or table.unpack
uv.new_thread({stack_size=0}, function(delay,s,null,bool,five,hw)
uv.new_thread({stack_size=0}, function(delay,s,null,bool,five,pi,hw)
assert(type(delay) == "number")
assert(type(s) == "string")
assert(null == nil)
assert(bool == false)
assert(five == 5)
assert(math.type(five) == 'integer')
squeek502 marked this conversation as resolved.
Show resolved Hide resolved
assert(pi == 3.14)
assert(hw == 'helloworld')
require('luv').sleep(delay)
end, unpack(args)):join()
Expand Down
Loading