tibia-client/modules/corelib
Konrad Kuśnierz 7ea6c46b2c Add binary operations for lua
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.
2015-05-18 21:38:05 +02:00
..
ui Add tab-spacing tag to MoveableTabBars 2015-04-20 03:32:32 +02:00
bitwise.lua Normalize source code 2012-07-28 02:07:57 -03:00
config.lua Keep g_settings as a 'static' variable rather than a direct object. 2014-04-01 16:51:38 +13:00
const.lua Fix locale send, spelllist reload, few changes 2013-02-18 22:18:10 -03:00
corelib.otmod Add binary operations for lua 2015-05-18 21:38:05 +02:00
globals.lua Add blink effect 2013-02-05 19:08:32 -02:00
inputmessage.lua Fix getColor, add/get position 2013-01-30 19:08:53 -02:00
keyboard.lua Fix keyboard unbind 2013-08-17 21:54:16 -03:00
math.lua Fix save of MiniWindow positions, issue #163 2013-01-16 17:57:05 -02:00
mouse.lua Market fix, and a few other things: 2013-02-13 05:14:16 +13:00
net.lua Minor fixes and improvements 2013-02-28 02:43:26 -03:00
outputmessage.lua Fix getColor, add/get position 2013-01-30 19:08:53 -02:00
settings.lua Fix to the makesingleton function. 2014-04-01 17:22:00 +13:00
string.lua string:contains() 2014-07-31 20:25:31 +02:00
struct.lua Add binary operations for lua 2015-05-18 21:38:05 +02:00
table.lua Fix table.equals 2014-07-09 17:00:10 +12:00
util.lua Tiny signalcall fix 2015-01-25 21:20:48 +01:00