Jump to content




mt's: calling strings?


  • You cannot reply to this topic
4 replies to this topic

#1 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 25 November 2016 - 06:53 PM

Is it possible to use mt's to make a string callable?

For example:
local stringCall = function(...)
end

local stringMT= {
  __call --or something like that
    = stringCall
}
--... you know the rest

So that I can do this:
'string'(argz)

?

#2 Admicos

  • Members
  • 207 posts
  • LocationTurkey

Posted 25 November 2016 - 07:40 PM

Probably, but why?

#3 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 25 November 2016 - 08:30 PM

I'm planning an making 2 api's, Libra and WEBer.
In the Libra api, I decided it's better to overwrite a nasty message saying 'attempt to call string' than overwrite somebodies beautiful functions.

So I choose to use strings.

Here's an example:
an example


#4 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 25 November 2016 - 08:47 PM

Edit:
Oh great.
There actually is a __call mt, but it only works on tables.
Is there any way I can call a string, though?

#5 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 26 November 2016 - 01:50 AM

View PostEveryOS, on 25 November 2016 - 08:47 PM, said:

Edit:
Oh great.
There actually is a __call mt, but it only works on tables.
Is there any way I can call a string, though?

Technically it's possible to get the metatable for strings, but bios.lua blocks access to it so you would have to modify that





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users