Advertisement
ForeverDev

Untitled

Oct 13th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. local properties = {
  2.     "Size", "Position", "Parent"
  3. }
  4.  
  5. local values = {
  6.     v3 = "Vector3.new",
  7.     cf = "CFrame.new"
  8. }
  9.  
  10. local getProperty = function(property)
  11.     for _, value in ipairs(properties) do
  12.         if value:lower():sub(1, #property) == property:lower() then
  13.             return value
  14.         end
  15.     end
  16.     return false
  17. end
  18.  
  19. local getValue = function(value)
  20.     for match, replace in pairs(values) do
  21.         value = value:gsub(match, replace)
  22.     end
  23.     return loadstring("return " .. value)()
  24. end
  25.  
  26. local define = function(class, parent)
  27.     return setmetatable({
  28.         class = class,
  29.         parent = parent,
  30.         props = {},
  31.         create = function(self)
  32.             local instance = Instance.new(self.class, self.parent)
  33.             for index, value in ipairs(self.props) do
  34.                 instance[value[1]] = value[2]
  35.             end
  36.             return instance
  37.         end
  38.     }, {
  39.         __newindex = function(self, key, value)
  40.             table.insert(self.props, {getProperty(key), getValue(value)})
  41.         end
  42.     })
  43. end
  44.  
  45. return define
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement