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