Forum

> > Off Topic > Function in function that looks like a table
Forums overviewOff Topic overviewLog in to reply

English Function in function that looks like a table

3 replies
To the start Previous 1 Next To the start

old Function in function that looks like a table

Gaios
Reviewer Off Offline

Quote
Title: what is it in lua?
This code works:
1
2
3
4
5
6
7
8
9
tab = {
  event = function() print(1) end;
}

function button()
  return tab
end

button().event()
How to do button().event().event()? Because double event gives me error.
1
2
3
button()
  .event()
  .event()

old Re: Function in function that looks like a table

Dousea
User Off Offline

Quote
These probably work.
1
2
3
4
5
6
7
8
9
10
11
12
13
tab = {}

function tab.event()
    print(1)
    
    return tab
end

function button()
    return tab
end

button().event().event()
or
1
2
3
4
5
6
7
8
9
10
11
12
13
tab = {}

function tab:event()
    print(1)
    
    return self
end

function button()
    return tab
end

button():event():event()
To the start Previous 1 Next To the start
Log in to replyOff Topic overviewForums overview