@@ -965,6 +965,13 @@ static int lpb_unpackfmt(lua_State *L, int idx, const char *fmt, lpb_SliceEx *s)
965
965
return rets ;
966
966
}
967
967
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
+
968
975
static int Lslice_new (lua_State * L ) {
969
976
lpb_Slice * s ;
970
977
lua_settop (L , 3 );
@@ -984,7 +991,7 @@ static int Lslice_libcall(lua_State *L) {
984
991
}
985
992
986
993
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 );
988
995
size_t size = lua_rawlen (L , 1 );
989
996
lpb_resetslice (L , s , size );
990
997
if (!lua_isnoneornil (L , 2 ))
@@ -993,16 +1000,16 @@ static int Lslice_reset(lua_State *L) {
993
1000
}
994
1001
995
1002
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 );
997
1004
lua_pushfstring (L , "pb.Slice: %p%s" , s ,
998
1005
lua_rawlen (L , 1 ) == sizeof (lpb_Slice ) ? "" : " (raw)" );
999
1006
return 1 ;
1000
1007
}
1001
1008
1002
1009
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 ));
1006
1013
return 2 ;
1007
1014
}
1008
1015
@@ -1013,13 +1020,6 @@ static int Lslice_unpack(lua_State *L) {
1013
1020
return lpb_unpackfmt (L , 3 , fmt , s );
1014
1021
}
1015
1022
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
-
1023
1023
static int Lslice_level (lua_State * L ) {
1024
1024
lpb_Slice * s = check_lslice (L , 1 );
1025
1025
if (!lua_isnoneornil (L , 2 )) {
0 commit comments