-- Copyright (C) 2012 by Yichun Zhang (agentzh) local ffi = require "ffi" local ffi_new = ffi.new local ffi_str = ffi.string local C = ffi.C local setmetatable = setmetatable local error = error local tonumber = tonumber module(...) _VERSION = '0.08' ffi.cdef[[ typedef unsigned char u_char; u_char * ngx_hex_dump(u_char *dst, const u_char *src, size_t len); intptr_t ngx_atoi(const unsigned char *line, size_t n); ]] local str_type = ffi.typeof("uint8_t[?]") function to_hex(s) local len = #s * 2 local buf = ffi_new(str_type, len) C.ngx_hex_dump(buf, s, #s) return ffi_str(buf, len) end function atoi(s) return tonumber(C.ngx_atoi(s, #s)) end local class_mt = { -- to prevent use of casual module global variables __newindex = function (table, key, val) error('attempt to write to undeclared variable "' .. key .. '"') end } setmetatable(_M, class_mt)