-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene.lua
More file actions
41 lines (37 loc) · 846 Bytes
/
Copy pathscene.lua
File metadata and controls
41 lines (37 loc) · 846 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
local scene = {}
scene.state = {}
function scene:__exit()
if self.state.onExit then self.state:onExit() end
end
function scene:__load()
if self.onLoad then self:onLoad() end
end
function scene:setScene(s)
self:__exit()
if self.current then
package.loaded[self.current] = nil
self.current = nil
end
self.state = nil
collectgarbage("collect")
self.state = require(s)
self.current = s
self:__load()
end
function scene:reload()
self:__exit()
if self.current then
package.loaded[self.current] = nil
end
self.state = nil
collectgarbage("collect")
self.state = require(self.current)
self:__load()
end
local mt = {
__index = function(table, key)
if table.state[key] then return table.state[key] end
end
}
setmetatable(scene, mt)
return scene