mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
add sproto double type (#1221)
Co-authored-by: zixun <lvzxiun@gmail.com>
This commit is contained in:
@@ -55,6 +55,13 @@ static int64_t lua_tointegerx(lua_State *L, int idx, int *isnum) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int lua_absindex (lua_State *L, int idx) {
|
||||
if (idx > 0 || idx <= LUA_REGISTRYINDEX)
|
||||
return idx;
|
||||
return lua_gettop(L) + idx + 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void
|
||||
@@ -235,6 +242,11 @@ encode(const struct sproto_arg *args) {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
case SPROTO_DOUBLE: {
|
||||
lua_Number v = lua_tonumber(L, -1);
|
||||
*(double*)args->value = (double)v;
|
||||
return 8;
|
||||
}
|
||||
case SPROTO_TBOOLEAN: {
|
||||
int v = lua_toboolean(L, -1);
|
||||
if (!lua_isboolean(L,-1)) {
|
||||
@@ -395,6 +407,11 @@ decode(const struct sproto_arg *args) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SPROTO_DOUBLE: {
|
||||
double v = *(double*)args->value;
|
||||
lua_pushnumber(L, v);
|
||||
break;
|
||||
}
|
||||
case SPROTO_TBOOLEAN: {
|
||||
int v = *(uint64_t*)args->value;
|
||||
lua_pushboolean(L,v);
|
||||
@@ -671,6 +688,9 @@ push_default(const struct sproto_arg *args, int array) {
|
||||
else
|
||||
lua_pushinteger(L, 0);
|
||||
break;
|
||||
case SPROTO_DOUBLE:
|
||||
lua_pushnumber(L, 0.0);
|
||||
break;
|
||||
case SPROTO_TBOOLEAN:
|
||||
lua_pushboolean(L, 0);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user