Skip to content

Commit 687dd09

Browse files
committed
minor changes
1 parent 0756a78 commit 687dd09

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

pb.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,13 @@ static int lpb_unpackfmt(lua_State *L, int idx, const char *fmt, lpb_SliceEx *s)
965965
return rets;
966966
}
967967

968+
static lpb_Slice *check_lslice(lua_State *L, int idx) {
969+
lpb_SliceEx *s = check_slice(L, idx);
970+
argcheck(L, lua_rawlen(L, 1) == sizeof(lpb_Slice),
971+
idx, "unsupport operation for raw mode slice");
972+
return (lpb_Slice*)s;
973+
}
974+
968975
static int Lslice_new(lua_State *L) {
969976
lpb_Slice *s;
970977
lua_settop(L, 3);
@@ -984,7 +991,7 @@ static int Lslice_libcall(lua_State *L) {
984991
}
985992

986993
static int Lslice_reset(lua_State *L) {
987-
lpb_Slice *s = (lpb_Slice*)check_slice(L, 1);
994+
lpb_Slice *s = check_lslice(L, 1);
988995
size_t size = lua_rawlen(L, 1);
989996
lpb_resetslice(L, s, size);
990997
if (!lua_isnoneornil(L, 2))
@@ -993,16 +1000,16 @@ static int Lslice_reset(lua_State *L) {
9931000
}
9941001

9951002
static int Lslice_tostring(lua_State *L) {
996-
lpb_Slice *s = (lpb_Slice*)check_slice(L, 1);
1003+
lpb_SliceEx *s = check_slice(L, 1);
9971004
lua_pushfstring(L, "pb.Slice: %p%s", s,
9981005
lua_rawlen(L, 1) == sizeof(lpb_Slice) ? "" : " (raw)");
9991006
return 1;
10001007
}
10011008

10021009
static int Lslice_len(lua_State *L) {
1003-
lpb_Slice *s = (lpb_Slice*)check_slice(L, 1);
1004-
lua_pushinteger(L, (lua_Integer)pb_len(s->curr.base));
1005-
lua_pushinteger(L, (lua_Integer)lpb_offset(&s->curr));
1010+
lpb_SliceEx *s = check_slice(L, 1);
1011+
lua_pushinteger(L, (lua_Integer)pb_len(s->base));
1012+
lua_pushinteger(L, (lua_Integer)lpb_offset(s));
10061013
return 2;
10071014
}
10081015

@@ -1013,13 +1020,6 @@ static int Lslice_unpack(lua_State *L) {
10131020
return lpb_unpackfmt(L, 3, fmt, s);
10141021
}
10151022

1016-
static lpb_Slice *check_lslice(lua_State *L, int idx) {
1017-
lpb_Slice *s = (lpb_Slice*)check_slice(L, idx);
1018-
argcheck(L, lua_rawlen(L, 1) == sizeof(lpb_Slice),
1019-
idx, "unsupport operation for raw mode slice");
1020-
return s;
1021-
}
1022-
10231023
static int Lslice_level(lua_State *L) {
10241024
lpb_Slice *s = check_lslice(L, 1);
10251025
if (!lua_isnoneornil(L, 2)) {

0 commit comments

Comments
 (0)