annotate util/hex.lua @ 6482:410067cdeb2f

net/server: If server.hook_signal exists, overwrite signal.signal; else make server.hook_signal == signal.signal No longer server_event specific server.hook_signal will always exist
author daurnimator <quae@daurnimator.com>
date Tue, 21 Oct 2014 17:26:48 -0400
parents 3f4809d01783
children ec566d7cd518
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6375
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local s_char = string.char;
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local function char_to_hex(c)
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 return ("%02x"):format(c:byte())
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 end
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local function hex_to_char(h)
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 return s_char(tonumber(h, 16));
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 end
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
6384
3f4809d01783 util.hex: Use locals!
Kim Alvefur <zash@zash.se>
parents: 6375
diff changeset
11 local function to(s)
6375
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 return s:gsub(".", char_to_hex);
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 end
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
6384
3f4809d01783 util.hex: Use locals!
Kim Alvefur <zash@zash.se>
parents: 6375
diff changeset
15 local function from(s)
6375
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 return s:gsub("..", hex_to_char);
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 end
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
76d8907d5301 util.hex: Small util lib for converting to/from hex strings
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 return { to = to, from = from }