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: Question

Previous Thread :: Next Thread 
AmazingSlayer1121 is not online. AmazingSlayer1121
Joined: 15 Aug 2010
Total Posts: 125
28 Mar 2011 03:49 PM
Is there any way to apply a metatable to act as a String in order to concancate the string by calling it with a string argument?
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
28 Mar 2011 03:51 PM
setmetatable(t, {__concat = function(a,b) return *whatever* end})
print(t.."Hello, World!")

The more important question is why do you want to?
Report Abuse
AmazingSlayer1121 is not online. AmazingSlayer1121
Joined: 15 Aug 2010
Total Posts: 125
28 Mar 2011 03:53 PM
@SNCPlay42

That's not exactly how I wanted to call it...

I wanted you be able to do something like this:

local str = String("Hello")
str(" world!")
print(str) ­ ­ ­ ­ ­ ­ ­--> Hello world!
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
28 Mar 2011 03:55 PM
Oh I see.

function String(str)
return setmetatable({str = str}, {
__call = function(t, arg)
t.str = t.str..arg
end,
__tostring = function(t) return t.str end
})
end
Report Abuse
AmazingSlayer1121 is not online. AmazingSlayer1121
Joined: 15 Aug 2010
Total Posts: 125
28 Mar 2011 03:56 PM
How many different metamethods exist? I've heard of __add, __sub, __div, __mul, __tostring, __call, and __concat. What else?
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
28 Mar 2011 04:00 PM
__pow - a ^ b
__concat - a..b
__unm - -a
__metatable (value, not function) - return value of getmetatable, prevents using setmetatable
__eq - a == b
__lt - a < b or b > a
__le - a <= b or b >= a
__mod - a % b
__len - #a
__gc - when a userdata is deleted

http://wiki.roblox.com/index.php/Metatables#Metamethods
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