Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _spook = { }
- local files = { "Extensions", "Instances", "Modules" }
- local extLoaded = false
- local vars = require(script:WaitForChild("Vars"))
- for _, file in pairs, files do
- script:WaitForChild(file)
- end
- function CopyTable(input)
- local result = { }
- if type(input) == "table" then
- for index, value in next, input, nil do
- result[CopyTable(index)] = CopyTable(value)
- end
- setmetatable(result, CopyTable(getmetatable(input)))
- else
- result = input
- end
- return result
- end
- function Wrap(input, data)
- local proxy, data = { }, CopyTable(data)
- proxy.__userdata = input
- data.__userdata = input
- setmetatable(proxy, {
- __index = function(self, index)
- local member = rawget(data, index)
- if member == nil then
- local success, result = pcall(function() return rawget(data, "__userdata")[index] end)
- if success then
- if type(result) == "function" then
- return function(_, ...)
- return result(rawget(data, "__userdata"), ...)
- end
- else
- return result
- end
- end
- else
- if type(member) == "function" then
- return function(_, ...)
- return member(proxy, ...)
- end
- else
- return member
- end
- end
- end,
- __newindex = function(self, index, value)
- local member = rawget(data, index)
- if member == nil then
- local success, _ = pcall(function() return rawget(proxy, "__userdata") end)
- if success then
- rawget(proxy, "__userdata")[index] = value
- end
- else
- rawset(data, index, value)
- end
- end,
- __metatable = { }
- })
- return proxy
- end
- return function()
- local env = getfenv(2)
- -- built-in
- do
- _spook.var = function(query)
- local result = vars[query]
- if result ~= nil then
- return result
- else
- warn("** Failed to load clientvar", query)
- end
- end
- _spook.wrap = function(input, data)
- return Wrap(input, data)
- end
- end
- -- enums
- do
- local new = { }
- for index, value in next, require(script:WaitForChild("Enums")) do
- new[index] = value
- end
- setmetatable(new, { __index = Enum })
- env["Enum"] = new
- end
- -- require
- do
- env["require"] = function(query)
- if type(query) == "string" then
- return require(script.Modules:WaitForChild(query))
- end
- return require(query)
- end
- end
- -- instance lib
- do
- env["Instance"] = {
- new = function(class, parent)
- local result = script.Instances:FindFirstChild(class)
- if result then
- local data = require(result)
- local userdata, api = data.__userdata, data.__api
- if userdata and type(userdata) == "userdata" then
- local clone = userdata:Clone()
- clone.Parent = parent
- return Wrap(clone, api)
- else
- return api
- end
- else
- return Instance.new(class, parent)
- end
- end
- }
- end
- -- printing
- do
- env["print"] = function(...)
- if vars.g_print_enabled then
- if vars.g_printPrefix_enabled then
- print(env.script.Name, "-", ...)
- else
- print(...)
- end
- end
- end
- end
- -- extensions
- do
- if not extLoaded then
- extLoaded = true
- for index, value in next, require(script.Extensions) do
- _spook[index] = value
- end
- end
- end
- return _spook
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement