This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
EveryOS's profile picture

return index running function

Started by EveryOS, 04 April 2016 - 03:27 PM
EveryOS #1
Posted 04 April 2016 - 05:27 PM
Let's say you had some code

table={
1,
2,
function explainSelf() return table end
}
Running table.explainSelf would clearly return the index the function is stored in

But what if we wanted to later do this:
otherTable={}
otherTable.explainSelf = table.explainSelf
Running otherTable.explainSelf would not return otherTable

So what would you do
Something like this?

function()
  return self
end
Edited on 04 April 2016 - 03:29 PM
KingofGamesYami #2
Posted 04 April 2016 - 06:18 PM
Where you say "index", I assume you mean "table". If it returned the index, it would return "explainSelf".

It'd look something like this:

local someTable = {
  explainSelf = function( self ) return self end,
}

someTable:explainSelf() --#note the : -- this is the same as
someTable.explainSelf( someTable ) --#<--that
EveryOS #3
Posted 04 April 2016 - 06:22 PM
Where you say "index", I assume you mean "table". If it returned the index, it would return "explainSelf".

It'd look something like this:

local someTable = {
  explainSelf = function( self ) return self end,
}

someTable:explainSelf() --#note the : -- this is the same as
someTable.explainSelf( someTable ) --#<--that
Thanks