Update README.md
This commit is contained in:
parent
072d17e039
commit
1568eb0c0d
28
README.md
28
README.md
@ -3,16 +3,20 @@ AS3 ByteArray class for lua.
|
|||||||
|
|
||||||
# usage
|
# usage
|
||||||
add the module:
|
add the module:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
luaopen_bytearr(L);
|
luaopen_bytearr(L);
|
||||||
```
|
```
|
||||||
|
|
||||||
# constructor
|
# constructor
|
||||||
create( [capacity, [endian]] ) - Create an empty byte array.
|
create( [capacity, [endian]] ) - Create an empty byte array.
|
||||||
|
|
||||||
init( [param1, param2, ...] ) - Create a byte array with initial bytes. Parameters should be a list of number or table.
|
init( [param1, param2, ...] ) - Create a byte array with initial bytes. Parameters should be a list of number or table.
|
||||||
|
|
||||||
load( str ) - Create a byte array with lua string object for read data. This byte array is read-only.
|
load( str ) - Create a byte array with lua string object for read data. This byte array is read-only.
|
||||||
|
|
||||||
return - A ByteArray object.
|
return - A ByteArray object.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local x = ByteArray.create() -- create an empty byte array
|
local x = ByteArray.create() -- create an empty byte array
|
||||||
local y = ByteArray.init( 0, 1, 2, 3 ) -- create a byte array with initial bytes
|
local y = ByteArray.init( 0, 1, 2, 3 ) -- create a byte array with initial bytes
|
||||||
@ -21,16 +25,25 @@ local z = ByteArray.load( "hello" ) -- create a byte array with a lua string obj
|
|||||||
|
|
||||||
# method for read data
|
# method for read data
|
||||||
readByte() - Read a 8-bit signed integer from byte array.
|
readByte() - Read a 8-bit signed integer from byte array.
|
||||||
|
|
||||||
readUnsignedByte() - Read a 8-bit unsigned integer from byte array.
|
readUnsignedByte() - Read a 8-bit unsigned integer from byte array.
|
||||||
|
|
||||||
readShort() - Read a 16-bit signed integer from byte array.
|
readShort() - Read a 16-bit signed integer from byte array.
|
||||||
|
|
||||||
readUnsignedShort() - Read a 16-bit unsigned integer from byte array.
|
readUnsignedShort() - Read a 16-bit unsigned integer from byte array.
|
||||||
|
|
||||||
readInt() - Read a 32-bit signed integer from byte array.
|
readInt() - Read a 32-bit signed integer from byte array.
|
||||||
|
|
||||||
readUnsignedInt() - Read a 32-bit unsigned integer from byte array.
|
readUnsignedInt() - Read a 32-bit unsigned integer from byte array.
|
||||||
|
|
||||||
readFloat() - Read a 32-bit float from byte array.
|
readFloat() - Read a 32-bit float from byte array.
|
||||||
|
|
||||||
readDouble() - Read a 64-bit float from byte array.
|
readDouble() - Read a 64-bit float from byte array.
|
||||||
|
|
||||||
readCString() - Read a string end with \0 from byte array.
|
readCString() - Read a string end with \0 from byte array.
|
||||||
|
|
||||||
return - A lua number object.
|
return - A lua number object.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local t = ByteArray.init( 1, 2, 3, 4, 5, 6 )
|
local t = ByteArray.init( 1, 2, 3, 4, 5, 6 )
|
||||||
local a = t:readByte() -- a == 1
|
local a = t:readByte() -- a == 1
|
||||||
@ -40,16 +53,25 @@ local c = t:readShort() -- c == 0x0403
|
|||||||
|
|
||||||
# method for write data
|
# method for write data
|
||||||
writeByte( s8 ) - Write a 8-bit signed integer to byte array.
|
writeByte( s8 ) - Write a 8-bit signed integer to byte array.
|
||||||
|
|
||||||
writeUnsignedByte( u8 ) - Write a 8-bit unsigned integer to byte array.
|
writeUnsignedByte( u8 ) - Write a 8-bit unsigned integer to byte array.
|
||||||
|
|
||||||
writeShort( s16 ) - Write a 16-bit signed integer to byte array.
|
writeShort( s16 ) - Write a 16-bit signed integer to byte array.
|
||||||
|
|
||||||
writeUnsignedShort( u16 ) - Write a 16-bit unsigned integer to byte array.
|
writeUnsignedShort( u16 ) - Write a 16-bit unsigned integer to byte array.
|
||||||
|
|
||||||
writeInt( s32 ) - Write a 32-bit signed integer to byte array.
|
writeInt( s32 ) - Write a 32-bit signed integer to byte array.
|
||||||
|
|
||||||
writeUnsignedInt( u32 ) - Write a 32-bit unsigned integer to byte array.
|
writeUnsignedInt( u32 ) - Write a 32-bit unsigned integer to byte array.
|
||||||
|
|
||||||
writeFloat( f32 ) - Write a 32-bit float to byte array.
|
writeFloat( f32 ) - Write a 32-bit float to byte array.
|
||||||
|
|
||||||
writeDouble( f64 ) - Write a 64-bit float to byte array.
|
writeDouble( f64 ) - Write a 64-bit float to byte array.
|
||||||
|
|
||||||
writeCString( str ) - write a string end with \0 to byte array.
|
writeCString( str ) - write a string end with \0 to byte array.
|
||||||
|
|
||||||
return - The ByteArray object itself.
|
return - The ByteArray object itself.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local buf = ByteArray.create()
|
local buf = ByteArray.create()
|
||||||
buf:writeByte(1):writeByte(2):writeInt(0x0403)
|
buf:writeByte(1):writeByte(2):writeInt(0x0403)
|
||||||
@ -57,7 +79,9 @@ buf:writeByte(1):writeByte(2):writeInt(0x0403)
|
|||||||
|
|
||||||
# method for copying data between ByteArray object
|
# method for copying data between ByteArray object
|
||||||
readBytes( to[, offset, length] ) - Read data to first parameter(a ByteArray object), the range for the target byte array is start from offset with length.
|
readBytes( to[, offset, length] ) - Read data to first parameter(a ByteArray object), the range for the target byte array is start from offset with length.
|
||||||
|
|
||||||
writeBytes( from[, offset, length] ) - Write data from first parameter(a ByteArray object), the range for the data is start from offset with length.
|
writeBytes( from[, offset, length] ) - Write data from first parameter(a ByteArray object), the range for the data is start from offset with length.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local buf = ByteArray.init( 1, 2, 3, 4, 5 )
|
local buf = ByteArray.init( 1, 2, 3, 4, 5 )
|
||||||
local d = ByteArray.create()
|
local d = ByteArray.create()
|
||||||
@ -66,6 +90,7 @@ buf:readBytes( d )
|
|||||||
|
|
||||||
# member position
|
# member position
|
||||||
start position for reading / writing data.
|
start position for reading / writing data.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local buf = ByteArray.init( 1, 2, 3, 4, 5 )
|
local buf = ByteArray.init( 1, 2, 3, 4, 5 )
|
||||||
buf.position = 3
|
buf.position = 3
|
||||||
@ -76,6 +101,7 @@ print( buf.position ) -- 5
|
|||||||
|
|
||||||
# member length
|
# member length
|
||||||
set / get length
|
set / get length
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local buf = ByteArray.init( 1,2,3,4,5,6,7 )
|
local buf = ByteArray.init( 1,2,3,4,5,6,7 )
|
||||||
print( buf.length )
|
print( buf.length )
|
||||||
@ -85,6 +111,7 @@ for i=1, #buf do print(buf[i]) end
|
|||||||
|
|
||||||
# member endian
|
# member endian
|
||||||
set / get endian
|
set / get endian
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local buf = ByteArray.init(2,3)
|
local buf = ByteArray.init(2,3)
|
||||||
buf.endian = ByteArray.LITTLE_ENDIAN
|
buf.endian = ByteArray.LITTLE_ENDIAN
|
||||||
@ -92,6 +119,7 @@ buf.endian = ByteArray.LITTLE_ENDIAN
|
|||||||
|
|
||||||
# indexing
|
# indexing
|
||||||
index start from 1 to length. If out of range, return -1.
|
index start from 1 to length. If out of range, return -1.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local buf = ByteArray.init(2,3)
|
local buf = ByteArray.init(2,3)
|
||||||
print(buf[1])
|
print(buf[1])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user