lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In the following 3 blogs I will update the spec for lua_Number in the packed
string, and for the format options for pack/unpack, and for the "background
info" / montivation for this... As these specs tend to be somehow "terrible
technical", so not nice to be read FIRST. As I expect FIRST readers read the
last blog first, I will post the motivation part at the end (so 2 blogs
after his one - this one starts with the lua_Number...).

Lua_Number CONVERTER FOR pack/unpack OPTION 'N'
(flexible length, supports ints, floats, Boolean, strings, nils in both
directions pack/unpack … for other types (functions, userdata, threads) pack
will push error message insert error code, and unpack with push error
message)

The “table error code” 0xF5 will be used only for non-nested-table command
options (t, ^, |, :, *).
The “table start/end codes 0xEA, 0xEB, 0xED will be used only for nested
table command option T.

Such an N command is coded by pack as a “Type byte” + possible follow-up
bytes (also zero follow-up bytes possible (for boolean, nil, error code,
nested table structure codes, or numbers 0...100 (marked "0B" then)).

The following table shows the Type byte, the number of follow-up bytes (e.
g. 0B, 4B, 8B, …), and the meaning:
0x00..0x64 0B int number 0…100
0x70..0x74 1/2/4/8/16B  number int8/int16/int32/int64/int128
0x71..0x74 2/4/8/16B  number float16/float32/float64/float128
0x81...0xD4 nB string with n Bytes, n=1…100
0xE0...0xE4 nB+1/2/4/8/16B string with n Bytes, n
int8/int16/int32/int64/int128
0xE0...0xE4 nB+1/2/4/8/16B string with n Bytes, n
int8/int16/int32/int64/int128
0xE8/0xE9 0B Boolean False/True
0xEA/0xEB/0xED 0B Table end, Table start, Hash start (only used for ‘T’
option)
0xF0 0B nil
0xF2...0xF8 0B Error "no_number" 0xF2=luserdata, 0xF5=table, 0xF6=function,
0xF7=userdata, 0xf8=thread (unpack will push an error, if it meets those in
the packed string…).

if named metatables should be allowed (see my new topic of today...), it
would also be nice to have a further type 0xEE or so for "metatable name"
following (followed by a string defining the metatable name - this would be
important for unpacking nested tables with metatable support functions...).



--
Sent from: http://lua.2524044.n2.nabble.com/Lua-l-f2524044.html