-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathram.lua
More file actions
executable file
·25 lines (25 loc) · 816 Bytes
/
ram.lua
File metadata and controls
executable file
·25 lines (25 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
return function(length, initial_value)
local self = {
size = length,
memory = {},
initialized = setmetatable({}, {
__index = function() return false end
}),
set_uninitialized_value = function(self, initial_value)
self.uninitialized_random = not initial_value
for i = 0, length - 1 do
if not self.initialized[i] then
self.memory[i] = initial_value or love.math.random(0, 255)
end
end
end
}
self:set_uninitialized_value(initial_value)
return setmetatable(self, {
__index = self.memory,
__newindex = function(self, address, value)
self.memory[address] = value
self.initialized[address] = true
end
})
end