Skip to content

Commit

Permalink
Merge pull request #8 from devSparkle/development
Browse files Browse the repository at this point in the history
Add support for NamedImports
  • Loading branch information
devSparkle authored Jul 16, 2023
2 parents 26d0db0 + 75b14d3 commit 78d222e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"robloxLsp.diagnostics.disable": [
"trailing-space"
]
}
2 changes: 1 addition & 1 deletion default.project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Overture",
"tree": {
"$path": "src/Overture.module.lua"
"$path": "src/Overture.lua"
}
}
30 changes: 27 additions & 3 deletions src/Overture.module.lua → src/Overture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ local function BindToTag(Tag: string, Function: (Instance) -> ()): RBXScriptConn
return CollectionService:GetInstanceAddedSignal(Tag):Connect(Function)
end

--[=[
@within Overture
@ignore
@param Module -- The ModuleScript to require
@param NamedImports -- When provided, returns the named variables instead of the entire ModuleScript
@return any?
]=]
local function RequireModule(Module: ModuleScript, NamedImports: {string}?)
if NamedImports then
local Exports = require(Module)
local Imports = {}

for ImportIndex, ImportName in ipairs(NamedImports) do
Imports[ImportIndex] = Exports[ImportName]
end

return unpack(Imports)
else
return require(Module)
end
end

--[=[
Finds a ModuleScript with the CollectionService `oLibrary` tag,
and returns the value that was returned by the given ModuleScript,
Expand Down Expand Up @@ -93,16 +116,17 @@ end
@yields
@param Index -- The name of the ModuleScript
@param NamedImports -- When provided, returns the named variables instead of the entire ModuleScript
@return any?
]=]
function Overture:LoadLibrary(Index: string)
function Overture:LoadLibrary(Index: string, NamedImports: {string}?)
if Libraries[Index] then
return require(Libraries[Index])
return RequireModule(Libraries[Index], NamedImports)
else
assert(not RunService:IsServer(), "The library \"" .. Index .. "\" does not exist!")

table.insert(LibraryThreadCache, {Thread = coroutine.running(), RequestedIndex = Index, RequestedAt = time()})
return require(coroutine.yield())
return RequireModule(coroutine.yield(), NamedImports)
end
end

Expand Down
10 changes: 10 additions & 0 deletions test-place.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Overture",
"tree": {
"$className": "DataModel",

"ReplicatedStorage": {
"$path": "src"
}
}
}
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "devsparkle/overture"
description = "Source code management engine for Roblox"
version = "2.0.1"
version = "2.1.0"
license = "MIT"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
Expand Down

0 comments on commit 78d222e

Please sign in to comment.