SSCaster (simple string caster) - simple module for converting strings to some objects and for calling functions.
It will be easier to show with a couple of examples demonstrating some capabilities of the module:
- “Enum.Material[‘Neon’]” → Neon material
- “game:GetService(‘ReplicatedStorage’).GameSettings:Clone()” → cloned GameSettings instance
- “warn(‘This will be printed in the console’)” → nil, and the message will be in the console
- “{true, Vector3.zero, {1.5, -2, nil}}” → { true, (0, 0, 0), { 1.5, -2, nil } }
Basic Usage
local ssc = require(Path.To.Module) -- Download at the bottom of the post
local success, result = pcall(function()
return ssc.Cast("game.Workspace") -- returns: Workspace
end)
if success then
print("yappy:")
print(result) -- Workspace
else
print("eh:")
error(result)
end
Settings
To change the settings, import the type from the module:
local sscSettings = ssc.StringCasterSettings
To create a settings object you can use StringCasterSettings.new{...}
:
local settings = sscSettings.new{}
List of all options
-
ValidateOnly
ValidateOnly: boolean = false
A mode for checking the validity of a string. When used, it returns either true (if no errors occurred) or false (if an error occurred).local mySettings = sscSettings.new{ValidateOnly = true} local result = ssc.Cast("game.Workspace", mySettings) print(result) -- true local result = ssc.Cast("emag:LoseSecondParent('Relaxgalaxy')", mySettings) -- it's like game:FindFirstChild('Workspace'), but, like, you know, different print(result) -- false
When used with SafeMode, it returns either true (if no errors occurred) or, if an error occurred, its message.
local mySettings = sscSettings.new{ValidateOnly = true, SafeMode = true} local result = ssc.Cast("Vector2int16.new(0, 32767890)", mySettings) print(result) -- true local result = ssc.Cast("error('%%%Trick...')", mySettings) print(result) -- Trick...
-
SafeMode
SafeMode: boolean = false
A mode that is used instead of pcall. It returns a table:
{
Result = [result, if no errors occurred],
Error = [error message, if one occurred]
}local mySettings = sscSettings.new{SafeMode = true} local result = ssc.Cast("game.Workspace", mySettings) print(result.Result, result.Error) -- Workspace nil local result = ssc.Cast("fredyFazber", mySettings) print(result.Result, result.Error) -- nil "Type 'fredyFazber' was not found"
When used with ValidateOnly, it returns either true (if no errors occurred) or, if an error occurred, its message.
local mySettings = sscSettings.new{ValidateOnly = true, SafeMode = true} local result = ssc.Cast("Vector2int16.new(0, 32767890)", mySettings) print(result) -- true local result = ssc.Cast("error('%%%Trick...')", mySettings) print(result) -- Trick...
-
DisablePropertyAccess
DisablePropertyAccess: boolean = false
Prohibits access to any properties of globals.local mySettings = sscSettings.new{DisablePropertyAccess = true} local success, result = pcall(function() return ssc.Cast("Enum", mySettings) end) if success then print(result) -- Enums else error(result) end local success, result = pcall(function() return ssc.Cast("Enum.Material", mySettings) end) if success then print(result) else error(result) -- SSCaster:859: Accessing properties is not allowed end
-
DisableFunctions
DisableFunctions: boolean = false
Prohibits calling any functions.local mySettings = sscSettings.new{DisableFunctions = true} local success, result = pcall(function() return ssc.Cast("Vector3.new", mySettings) end) if success then print(result) -- function: 0x... -- (because we didn't call the function, we just received it) else error(result) end local success, result = pcall(function() return ssc.Cast("Vector3.new()", mySettings) end) if success then print(result) else error(result) -- SSCaster:859: Function calls are not allowed end
-
Custom
Custom: table = {}
A list of custom globals.local myCustomGlobals = { ["ssc"] = ssc } local success, result = pcall(function() return ssc.Cast( "ssc.Cast('Vector3.new(1, 2, 3)')", sscSettings.new{Custom = myCustomGlobals} ) end) if success then print(result) -- 1, 2, 3 else error(result) end
-
AllowedGlobals
AllowedGlobals: table = nil
A list of all globals that are allowed to be used. If a string contains a global that is not in this list, an error is raised. Does not work with BlockedGlobals.local mySettings = sscSettings.new{AllowedGlobals = {Vector3}} local success, result = pcall(function() return ssc.Cast("Vector3.new(1, 2, 3)", mySettings) end) if success then print(result) -- 1, 2, 3 else error(result) end local success, result = pcall(function() return ssc.Cast("os.clock()", mySettings) end) if success then print(result) else error(result) -- SSCaster:859: Global 'os' is not allowed end
-
BlockedGlobals
BlockedGlobals: table = nil
A list of all globals that are blocked from being used. If a string contains a global that is in this list, an error is raised. Does not work with AllowedGlobals.local mySettings = sscSettings.new{BlockedGlobals = {Vector3}} local success, result = pcall(function() return ssc.Cast("os.clock()", mySettings) end) if success then print(result) -- 1047350.8672366 else error(result) end local success, result = pcall(function() return ssc.Cast("Vector3.new(1, 2, 3)", mySettings) end) if success then print(result) else error(result) -- SSCaster:859: Global 'Vector3' is not allowed end
-
AllowedFunctions
AllowedFunctions: table = nil
A list of all functions that are allowed to be used. If the string contains a function that is not in this list, an error will be raised. Does not workwith BlockedFunctions.local mySettings = sscSettings.new{AllowedFunctions = {Vector3.new}} local success, result = pcall(function() return ssc.Cast("Vector3.new(1, 2, 3)", mySettings) end) if success then print(result) -- 1, 2, 3 else error(result) end local success, result = pcall(function() return ssc.Cast("Vector3.FromNormalId(Enum.NormalId.Front)", mySettings) end) if success then print(result) else error(result) -- SSCaster:859: Used function is not allowed end local success, result = pcall(function() return ssc.Cast("Enum.NormalId.Front", mySettings) end) if success then print(result) -- Front -- (because no functions were used) else error(result) end
-
BlockedFunctions
BlockedFunctions: table = nil
A list of all functions that are prohibited from use. If the string contains a function that is in this list, an error will be raised. Does not work with AllowedFunctions.local mySettings = sscSettings.new{BlockedFunctions = {Vector3.new}} local success, result = pcall(function() return ssc.Cast("Vector3.new(1, 2, 3)", mySettings) end) if success then print(result) else error(result) -- SSCaster:859: Used function is not allowed end local success, result = pcall(function() return ssc.Cast("Vector3.FromNormalId(Enum.NormalId.Front)", mySettings) end) if success then print(result) -- 0, 0, -1 else error(result) end
-
AllowedReturnTypes
AllowedReturnTypes: table = nil
A list of all allowed return types. If the string returns a type that is not in this list, an error will be raised. Does not stack with BlockedReturnTypes.local mySettings = sscSettings.new{AllowedReturnTypes = {"boolean", "Vector3", "function"}} local success, result = pcall(function() return ssc.Cast("Vector3.zero", mySettings) end) if success then print(result) -- 0, 0, 0 else error(result) end local success, result = pcall(function() return ssc.Cast("{true, Vector3.zero}", mySettings) end) if success then print(result) else error(result) -- SSCaster:859: Wrong result type -- (because it is a table) end
-
BlockedReturnTypes
BlockedReturnTypes: table = nil
A list of all prohibited return types. If the string returns a type that is in this list, an error will be raised. Does not stack with AllowedReturnTypes.local mySettings = sscSettings.new{BlockedReturnTypes = {"boolean"}} local success, result = pcall(function() return ssc.Cast("os.clock()", mySettings) end) if success then print(result) -- 1049628.8949082 else error(result) end local success, result = pcall(function() return ssc.Cast("true", mySettings) end) if success then print(result) else error(result) -- SSCaster:859: Wrong result type end
To use ready-made useful settings presets, use StringCasterSettings.mode({modes}, overwrittenSettings)
:
local settings = sscSettings.mode()
List of all presets
-
noerror
SafeMode = true
-
validate
ValidateOnly = true
SafeMode = true -
object
AllowedGlobals = {game}
DisableFunctions = true
AllowedReturnTypes = {“Instance”}Additional modes:
property
AllowedReturnTypes = nil
-
enum
AllowedGlobals = {Enum}
AllowedReturnTypes = {“Enum”, “EnumItem”}Additional modes:
enumonly
AllowedReturnTypes = {“Enum”}
enumitemonly
AllowedReturnTypes = {“EnumItem”}
-
basic
finalSettings.AllowedGlobals = {}
DisableFunctions = true
Example:
local mySettings = sscSettings.mode("noerror")
local result = ssc.Cast("os.clock()", mySettings)
print(result.Result, result.Error) -- 1057670.0072464 nil
local mySettings = sscSettings.mode(
{"noerror", "enum", "enumitemonly"},
sscSettings.new{DisableFunctions = true}
)
local result = ssc.Cast("Enum.Material.Neon", mySettings)
print(result.Result, result.Error) -- Enum.Material.Neon nil
Note
Using the module can be dangerous, for example, it can be used to change and delete any objects, so it is recommended to:
- make sure that all user content is NEVER called on the server side and is always processed only on the client side.
- use settings with restrictions for narrowly focused tasks (for example, if you use caster only to get an Enum from a string, use enum mode)
The module may contain errors, bugs and shortcomings, so please report them in the comments.
There will never be any updates to the module (POSSIBLY except for bug fixes).
This is a simple parser, in which you cannot create variables, functions, perform mathematical calculations, and it is created mostly only for simple tasks.
The module and all the code from it can be freely used anywhere without mentioning the source.