Skip to content

Commit

Permalink
Merge pull request torch#4 from colesbury/master
Browse files Browse the repository at this point in the history
Support LuaFFI
  • Loading branch information
soumith committed May 1, 2015
2 parents 05ceb9c + 3fdf4d6 commit 735f6cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion elem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions hash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 735f6cd

Please sign in to comment.