Buffer:from(var, [encoding]) method
Reinitialize the Buffer with the specified content.
Parameters
var
A variable used to initialize the Buffer. Only number, string and table values are permitted with the following behavior :
- number : Initialize the Buffer with the specified size. All bytes are initialized to zero.
- string : Initialize the Buffer with the specified string. An optional encoding argument can specify how to interpret the string (see below)
- table : Initialize the Buffer with the specified table. The table must contain only sequential byte values (for example { 20, 33, 75 })
encoding
An optional string used to specify the encoding when initializing the Buffer with a string value :
- "utf8" : Initialize the Buffer with a UTF8 string encoding, or as raw binary data (default)
- "unicode" : Initialize the Buffer with an UNICODE (UCS-2 LE) encoded string
- "base64" : Initialize the Buffer with a base64 encoded string
- "hex" : Initialize the Buffer with a hexadecimal encoded string
Return value
Returns no value.Example
-- init a Buffer with one byte
local buff = sys.Buffer(1)
-- update buff content with a string
buff:from("This is a string");
print(buff) --Outputs This is a string