Skip to content

Commit 7b0ad72

Browse files
authored
Merge pull request #77 from thesabinelim/create-object
basalt.createObject()
2 parents 35113e2 + e874863 commit 7b0ad72

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

Basalt/main.lua

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ local getVariable = function(name)
7070
return variables[name]
7171
end
7272

73+
local getObjects = function()
74+
return moddedObjects
75+
end
76+
77+
local getObject = function(id)
78+
return getObjects()[id]
79+
end
80+
81+
local createObject = function(objectName, id, basalt)
82+
return getObject(objectName)(id, basalt)
83+
end
84+
7385
local bInstance = {
7486
getDynamicValueEventSetting = function()
7587
return basalt.dynamicValueEvents
@@ -127,14 +139,12 @@ local bInstance = {
127139
stop = stop,
128140
debug = basalt.debug,
129141
log = basalt.log,
142+
143+
getObjects = getObjects,
130144

131-
getObjects = function()
132-
return moddedObjects
133-
end,
145+
getObject = getObject,
134146

135-
getObject = function(id)
136-
return moddedObjects[id]
137-
end,
147+
createObject = createObject,
138148

139149
getDirectory = function()
140150
return projectDirectory

Basalt/objects/Container.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,9 @@ return function(name, basalt)
384384
end
385385
end
386386

387-
for k,v in pairs(basalt.getObjects())do
388-
container["add"..k] = function(self, name)
389-
return addObject(self, v(name, basalt))
387+
for objectName, _ in pairs(basalt.getObjects()) do
388+
container["add" .. objectName] = function(self, id)
389+
return addObject(self, basalt.createObject(objectName, id, basalt))
390390
end
391391
end
392392

Basalt/objects/Flexbox.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ return function(name, basalt)
101101
end,
102102
}
103103

104-
for k,v in pairs(basalt.getObjects())do
105-
object["add"..k] = function(self, name)
106-
local obj = base["add"..k](self, name)
104+
for objectName, _ in pairs(basalt.getObjects()) do
105+
object["add" .. objectName] = function(self, id)
106+
local obj = base["add" .. objectName](self, id)
107107
applyLayout(base)
108108
return obj
109109
end

0 commit comments

Comments
 (0)