Skip to content

Commit

Permalink
hash: fixed issue of <pairs> (or other metatable members) seen as key…
Browse files Browse the repository at this point in the history
… values
  • Loading branch information
andresy committed Apr 5, 2015
1 parent 3ddf16d commit 05ceb9c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions hash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ function hash:__index(lkey)
if obj ~= nil then
local val = elem.get(C.tds_hash_object_value(obj))
return val
else
return rawget(hash, lkey)
end
end

Expand All @@ -82,21 +80,19 @@ function hash:__pairs()
end
end

hash.pairs = hash.__pairs

ffi.metatype('tds_hash', hash)

if pcall(require, 'torch') and torch.metatype then

function hash:write(f)
f:writeLong(self:__len())
function hash:__write(f)
f:writeLong(#self)
for k,v in pairs(self) do
f:writeObject(k)
f:writeObject(v)
end
end

function hash:read(f)
function hash:__read(f)
local n = f:readLong()
for i=1,n do
local k = f:readObject()
Expand Down

0 comments on commit 05ceb9c

Please sign in to comment.