How would I make the Metatable variable return something other than the table?
Example = setmetatable({}, {
__index = function(self, i)
return workspace
end
})
print(Example)
Like to make Example return a instance
How would I make the Metatable variable return something other than the table?
Example = setmetatable({}, {
__index = function(self, i)
return workspace
end
})
print(Example)
Like to make Example return a instance
In your instance, You would do
print(Example.someObscurlyNilIndexThatWillMakeTgisReturnWorkspace)
You cannot do this. However, if you supply a __call metamethod that returns your instance, you can use Example() to get the instance.
Example = setmetatable({}, {
__index = workspace,
__call = function() return workspace end
})
print(Example())
--> Workspace
We used to be able to edit the metatables of in-game objects, but they have been locked for a very long time.
Edit: Alternatively, you can check out my small project and see if it suits your needs.
Not practical for my purpose of needing it.
You can take my Custom Hierarchy model and see if it suits your needs.
I just need it for the variable. :/
This discussion is preserved as it was. New answers, comments, and votes are closed.
10 comments
I need the variable of Example return something other than a table...
Can you explain further what you are trying to do?
Because, http://puu.sh/8aG3t.txt I cannot use just the variable of a created object to parent a object to it....
So I'm not entirely understanding so bare with me. When you call an index from ObjectController... It returns something like a property, correct? So you want to just return the object instead...?
In this case Instance.new("Part").Parent = Instance.new("Part") errors due to the metatable variable returning a table value. I was wondering if it was possible to change it so the variable doesn't return a table but a Instance/Userdata instead.
Heh... I'm sorry to say this but ROBLOX limitations with what they lock does not allow this to happen. You have to probably add another index to the object that is equal to the Instance.
Meh, I guess I will have to custom code my own fenv... Wish me luck I'm going in deep i~i
Are you asking for a way to create a userdata? Use newproxy.
Can I point said userdata to an Instance :D?
Well, what he is doing is creating a kind of replacement for the Instance table with metatable extensions. If anyone knows a solution, give a call.