Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CoolCredits = ' \n'..
- 'Create wrapped instances easily for scripters who really love Object-Oriented Programming! '..
- ' \n\n'..
- ' - SoftlockedUnderZero '
- Documentation = {
- Notes = {
- ' - Auto-suggest does not work here.'
- };
- Constructor_Function = {
- ParameterInformation = {
- Real_Instance = [[ M (Instance)
- Targeted Instance to be wrapped.
- ]];
- Properties = [[ M (table (dictionary))
- A dictionary where the index is the property name and a value which is a function or array
- that has the function as the first value.
- So it should/can look like this:
- {
- Property1Name = function(a,b,c)end;
- Property2Name = {
- function(a,b,c)end;
- <variant default value>
- 'readonly';
- -- ... other property tags/restrictions
- }
- }
- The parmeters for the function are as follows:
- Instance: Real_Instance
- string: Property Name
- variant: New Value
- If you're using an array instead a function for a value, the extra values are for restrictions
- you would like to put on your properties.
- Currently there are:
- 'readonly' Disables the ability to overwrite a property.
- ]];
- Functions = [[ M (function)
- Should look like this:
- {
- FunctionNameIndex = <function>;
- }
- where the function is:
- function(Instance: RealInstance, ... tuple)
- end
- ]];
- Events = [[ M (function)
- Still polishing this section.
- ]]
- }
- }
- }
- local spawn = function(a)
- coroutine.wrap(a)()
- end
- local wait = require(6120706882)
- local PropertyTags = {
- readonly = function(_,_,_,a)
- assert(not a,'This property is read-only')
- end
- }
- local Wrap = {
- new = function(Real_Instance,Properties,Functions,Events,OtherSettings)
- local Indexed = {}
- local NewIndexed = {}
- local StoredPropertyValues = {}
- for a,b in next,Properties do
- local Func1 = type(b)=='table'and b[1]or b
- local PropertyTags1 = {}
- if type(b)=='table'then
- StoredPropertyValues[a] = b[2]
- for _,c in next,{table.unpack(b,3)}do
- local d = PropertyTags[c]
- assert(d,'non-existant property tag')
- table.insert(PropertyTags1,d)
- end
- end
- Indexed[a] = function(c)
- local d = {Real_Instance,c,StoredPropertyValues[a],false}
- if#PropertyTags1>0 then
- for _,a in next,PropertyTags1 do
- a(unpack(d))
- end
- end
- return Func1(unpack(d))
- end
- NewIndexed[a] = function(c,d)
- local d = {Real_Instance,c,d,true}
- if#PropertyTags1>0 then
- for _,a in next,PropertyTags1 do
- a(unpack(d))
- end
- end
- StoredPropertyValues[a] = Func1(unpack(d))
- end
- end
- for a,b in next,Functions do
- Indexed[a] = function()
- return function(_,...)
- return b(Real_Instance,...)
- end
- end
- end
- for a,b in next,Events do
- local Eventlist = {}
- spawn(function()
- repeat
- local c = {b()}
- if c[1]then
- for _,d in next,Eventlist do
- if not d then continue;end;
- d(table.unpack(c,2))
- end
- end
- wait()
- until nil
- end)
- local RBXEventSet = {
- Connect = function(_,c)
- table.insert(Eventlist,c)
- return{
- Disconnect = function()
- local a = table.find(Eventlist,c)
- if not a then return;end;
- table.remove(Eventlist,a)
- end
- }
- end;
- Wait = function()
- local c
- repeat
- c = {b()}
- wait()
- until c[1]
- return table.unpack(c,2)
- end
- }
- Indexed[a] = function()
- return RBXEventSet
- end
- end
- local MT = setmetatable({},{
- __index = function(_,ind)
- local a = Indexed[ind]
- assert(a,'Bad index'..ind)
- return a(ind)
- end;
- __newindex = function(_,ind,nv)
- local a = NewIndexed[ind]
- assert(a,'No property')
- a(ind,nv)
- end
- })
- return MT
- end
- }
- return Wrap
Add Comment
Please, Sign In to add comment