Skip to content

Commit

Permalink
Metamethods __atindex and __len for records
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Feb 11, 2020
1 parent a6e8bca commit 6852faf
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 317 deletions.
19 changes: 14 additions & 5 deletions lib/myarraytable.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
## strict = true
## unitname = 'nelua'

require 'allocators.gc_allocator'

local allocator = @gc_allocator

## local memoize = require 'nelua.utils.memoize'
## myarraytable = hygienize(memoize(function(T)
## myarraytable = hygienize(memoize(function(T, allocator)
## if allocator then
local allocator = #[allocator]#
## else
require 'allocators.gc_allocator'
local allocator = @gc_allocator
## end

local T = @#[T]#
local ArrayTableImplT <codename #['nelua_ArrayTableImpl_'..T.name]#> = @record {
size: usize,
Expand All @@ -25,6 +28,12 @@ local allocator = @gc_allocator
end
end

function ArrayTableT.create(): ArrayTableT <inline>
local self: ArrayTableT
self:init()
return self
end

function ArrayTableT:reset()
if likely(self.impl) then
allocator.spandealloc(self.impl.data)
Expand Down
Loading

0 comments on commit 6852faf

Please sign in to comment.