From eec3f9e44bee334542348bdd1d428417e22ed5e5 Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Wed, 21 Jan 2015 14:37:41 +0100 Subject: use Lua 5.3's source for string packing --- compat53.lua | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'compat53.lua') diff --git a/compat53.lua b/compat53.lua index 67a8c8f..4a78260 100644 --- a/compat53.lua +++ b/compat53.lua @@ -46,15 +46,24 @@ if lua_version < "5.3" then end - -- use Roberto's struct module for string packing/unpacking for now - -- maybe we'll later extract the functions from the 5.3 string - -- library for greater compatiblity, but it uses the 5.3 buffer API - -- which cannot easily be backported to Lua 5.1. - local struct_ok, struct = pcall(require, "struct") - if struct_ok then - string.pack = struct.pack - string.packsize = struct.size - string.unpack = struct.unpack + -- load string packing functions + local str_ok, strlib = pcall(require, "compat53.string") + if str_ok then + for k,v in pairs(strlib) do + string[k] = v + end + end + + + -- try Roberto's struct module for string packing/unpacking if + -- compat53.string is unavailable + if not str_ok then + local struct_ok, struct = pcall(require, "struct") + if struct_ok then + string.pack = struct.pack + string.packsize = struct.size + string.unpack = struct.unpack + end end -- cgit v1.2.3-55-g6feb