mirror of
https://github.com/edubart/otclient.git
synced 2025-04-30 09:39:21 +02:00

This is something I was always missing - posibbility to operate on binary files or streams in pure lua. In most cases we do only need to read simple variables from files such as integers with different amount of bytes. This "class" will provide that ability. It's a simple implementation of following C module for lua: http://www.inf.puc-rio.br/~roberto/struct/ It has much less, though. Following elements have been implemented: ">" flag to set mode to big endian. "<" flag to set mode to little endian. "b" a signed char. "B" an unsigned char. "h" a signed short (2 bytes). "H" an unsigned short (2 bytes). "i" a signed int (4 bytes). "I" an unsigned int (4 bytes). "l" a signed long (8 bytes). "L" an unsigned long (8 bytes). "s" a zero-terminated string. An example how to use it: ```lua local packed = Struct.pack('<LIhBsb', 123456789123456789, 123456789, -3200, 255, 'Test message', -1) -- packed is now a lua string we can save to file as binary data local L, I, h, B, s, b = Struct.unpack('<LIhBsb', packed) print(L, I, h, B, s, b) ``` You can use g_resources.readFileContents as function to read binary files and parse them via this class.
28 lines
548 B
Plaintext
28 lines
548 B
Plaintext
Module
|
|
name: corelib
|
|
description: Contains core lua classes, functions and constants used by other modules
|
|
author: OTClient team
|
|
website: www.otclient.info
|
|
reloadable: false
|
|
|
|
@onLoad: |
|
|
dofile 'math'
|
|
dofile 'string'
|
|
dofile 'table'
|
|
dofile 'bitwise'
|
|
dofile 'struct'
|
|
|
|
dofile 'const'
|
|
dofile 'util'
|
|
dofile 'globals'
|
|
dofile 'config'
|
|
dofile 'settings'
|
|
dofile 'keyboard'
|
|
dofile 'mouse'
|
|
dofile 'net'
|
|
|
|
dofiles 'classes'
|
|
dofiles 'ui'
|
|
|
|
dofile 'inputmessage'
|
|
dofile 'outputmessage' |