generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: metatables

Previous Thread :: Next Thread 
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
06 Feb 2017 06:07 PM
how can metafunctions be used to define methods, i.e: part:Explode() (creates an explosion within said part at that part's location then destroys/deletes the part)
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
06 Feb 2017 06:08 PM
i meant metamethods but u get the idea
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
06 Feb 2017 06:08 PM
please don't give a response like: "__index can be a function or a table", im aware of that much.
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
06 Feb 2017 06:16 PM
bump
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Feb 2017 06:17 PM
You don't have to use metatables. If you insist:
"__index can be a function or a table"

local t = setmetatable({1, 2, 3}, {__index=table})
print(t:concat(", "))
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
06 Feb 2017 06:18 PM
how else would you go about it then? i don't want to use a function
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Feb 2017 06:19 PM
I didn't use a function.
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
06 Feb 2017 06:21 PM
i know but u said there were other ways besides that
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Feb 2017 06:22 PM
local a = { x = 1,
printX = function(self) print(self.x) end
}

a:printX()
Report Abuse
FumeiSencho is not online. FumeiSencho
Joined: 07 Apr 2013
Total Posts: 452
06 Feb 2017 06:22 PM
xinst = newproxy(true)
proxytable = {}
print(type(xinst)) --> userdata
setmetatable(xinst, {__index = proxytable})

function proxytable:printhi()
print("hi from " .. self)
end

xinst:printhi()

i don't think i messed up, that should print "hi from userdata: some hexadecimal memory address"


Report Abuse
FumeiSencho is not online. FumeiSencho
Joined: 07 Apr 2013
Total Posts: 452
06 Feb 2017 06:24 PM
oh i think you have to do getmetatable(xinst).__index = proxytable instead of using setmetatable

pretty much the same though


Report Abuse
AxonMega is online. AxonMega
Joined: 29 Aug 2014
Total Posts: 2403
06 Feb 2017 06:24 PM
You don't need metatables to define methods, only metamethods. You can use metatables for that if you want; when you index a table, Lua checks if there is value at the index in the metatable.

And my friggin autocorrect keeps changing metatable to meatball.
Report Abuse
foreverpower is not online. foreverpower
Joined: 05 Feb 2011
Total Posts: 5578
06 Feb 2017 06:24 PM
@cntkillme

But that does not add methods to an existing instance.


Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
06 Feb 2017 06:24 PM
thanks, i appreciate it
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Feb 2017 06:26 PM
"But that does not add methods to an existing instance."
It's impossible to do that.
The closest you can get is by wrapping your instance and everything else so it can handle wrapped instances correctly and pretend it's the real instance.
Report Abuse
foreverpower is not online. foreverpower
Joined: 05 Feb 2011
Total Posts: 5578
06 Feb 2017 06:27 PM
^

Which is the same thing, at least to the caller.


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image