From 40745c4f6fa7c00419f6f5da77fbeefeff297161 Mon Sep 17 00:00:00 2001 From: unittensor Date: Mon, 22 Jan 2024 23:28:21 -0500 Subject: [PATCH] roblox sandbox maybe --- luau/tests/RobloxSandbox.lua | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 luau/tests/RobloxSandbox.lua diff --git a/luau/tests/RobloxSandbox.lua b/luau/tests/RobloxSandbox.lua new file mode 100644 index 0000000..6f78d91 --- /dev/null +++ b/luau/tests/RobloxSandbox.lua @@ -0,0 +1,52 @@ +type workspace = {[string]: {number}} +type Service = {} + +export type exports = {[string]: {workspace | number | {}}} + +local workspace: workspace = {} +local RS = { + RenderStepped = {}, + Stepped = {}, + Heartbeat = {} +} +local game = setmetatable({ + Workspace = workspace, + Players = {}, + RunService = RS +}, { + __index = function(self,i) + return rawget(self,i) + end, + __newindex = function(self,i,_) + --Roblox actually does this + local t = type(i) + return t == "Object" and "Unable to assign property Game. Property is read only" or `Unable to assign property Game. Object expected, got {t}` + end, + __metatable = "This metatable is locked." +}) + +function game:GetService(service: string): Service + return self[service] +end +function game:service(service: string): Service + return self:GetService(service) +end +function game:FindService(service: string): boolean | Service + return self[service] and self[service] +end + +local tick = os.clock() --just be better (Roblox wants you to use this instead of "tick" anyways because of Wine) +local task = { + wait = {}, + delay = {}, + defer = {} +} + +local exports: exports = { + game = game, Game = game, + workspace = workspace, Workspace = workspace, + tick = tick, + task = task +} + +return exports \ No newline at end of file