Last active
June 7, 2021 00:24
-
-
Save Vurv78/7f49f9556b3377435c1bc95201887001 to your computer and use it in GitHub Desktop.
Adding _G access to starfall safely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function addModule(name, exec) | |
if not SF.Modules then error("SF Modules table doesn't exist!") end | |
SF.Modules[name] = { | |
["injected"] = {init = exec()} | |
} | |
end | |
local function reloadSFEditor() | |
pcall(function() | |
if SF.Editor.initialized then | |
SF.Editor.editor:Close() | |
for k, v in pairs(SF.Editor.TabHandlers) do | |
if v.Cleanup then v:Cleanup() end | |
end | |
SF.Editor.initialized = false | |
SF.Editor.editor:Remove() | |
SF.Editor.editor = nil | |
end | |
end) | |
include("starfall/editor/editor.lua") | |
end | |
addModule("env", function() | |
local registerPrivilege = SF.Permissions.registerPrivilege | |
registerPrivilege("env", "_G", "Whether everyone can use _G. Don't set this to everyone please.", { | |
client = { | |
default = 4 -- [1] ONLY YOU, [2] ANYONE, [3] FRIENDS, [4] NO ONE | |
} | |
}) | |
-- Reload all of the permissions manually | |
SF.Permissions.loadPermissionOptions() | |
-- Add documentation for env() | |
SF.Docs.Libraries.builtins.methods.env = { | |
class = "function", | |
description = "Returns _G, requires permission 'env'", | |
name = "env", | |
path = "libs_sh/builtins.lua#L69", | |
realm = "client", | |
returns = { | |
[1] = { | |
description = "Lua's global table.", | |
type = "table" | |
} | |
} | |
} | |
-- Reload the SF Editor so that functions like env() highlight with the documentation. | |
reloadSFEditor() | |
return function(instance) | |
local checkpermission = SF.Permissions.check | |
local builtins_library = instance.env | |
local eunwrap = instance.Types.Entity.Unwrap | |
--- Returns _G, requires permission 'env' | |
-- @return table _G | |
function builtins_library.env() | |
checkpermission(instance, nil, "env") | |
return _G | |
end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment