From 3fdf4d69e5afed1b35e6800c346ae1763a373826 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Fri, 1 May 2015 16:09:33 -0400 Subject: [PATCH] Support LuaFFI --- elem.lua | 2 +- hash.lua | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/elem.lua b/elem.lua index cf687f7..94bd75d 100644 --- a/elem.lua +++ b/elem.lua @@ -37,7 +37,7 @@ function elem.get(celem) local value = C.tds_elem_get_number(celem) return value elseif elemtype == 115 then--string.byte('s') then - local value = ffi.string(C.tds_elem_get_string(celem), C.tds_elem_get_string_size(celem)) + local value = ffi.string(C.tds_elem_get_string(celem), tonumber(C.tds_elem_get_string_size(celem))) return value elseif elemtype == 112 then--string.byte('p') then local lelem_p = C.tds_elem_get_pointer(celem) diff --git a/hash.lua b/hash.lua index 7e5d4b1..ec2f37e 100644 --- a/hash.lua +++ b/hash.lua @@ -4,10 +4,11 @@ local elem = require 'tds.elem' local C = tds.C local hash = {} +local NULL = not jit and ffi.C.NULL or nil function hash.__new() local self = C.tds_hash_new() - if self == nil then + if self == NULL then error('unable to allocate hash') end self = ffi.cast('tds_hash&', self) @@ -30,7 +31,7 @@ end function hash:__newindex(lkey, lval) assert(self) local obj = findkey(self, lkey) - if obj ~= nil then + if obj ~= NULL then if lval then local val = C.tds_hash_object_value(obj) C.tds_elem_free_content(val) @@ -54,7 +55,7 @@ end function hash:__index(lkey) assert(self) local obj = findkey(self, lkey) - if obj ~= nil then + if obj ~= NULL then local val = elem.get(C.tds_hash_object_value(obj)) return val end @@ -72,7 +73,7 @@ function hash:__pairs() return function() local obj = C.tds_hash_iterator_next(iterator) - if obj ~= nil then + if obj ~= NULL then local key = elem.get(C.tds_hash_object_key(obj)) local val = elem.get(C.tds_hash_object_value(obj)) return key, val