2014-10-29 1 views
1

내가 나에게주고있는이 같은 표를 얻었다 '('는 구문 오류가 있어야 의미 'errorline'중첩 테이블 구문의 개체 기능?

에서 't'근처 예상하지만,

그럴 수 없어 하나를 감지하면 구문 뭐가 잘못 어떤 생각을 가지고

t = {} 

t[x] = { 
    some = "data", 

    foo = function() return "bar" end, 

    elements = { -- the class is working 100%, have used it for several projects. 
    mon = class:new(param), 
    tue = class:new(param2), 
    n = class:new(param3), 
    }, 

    function t[x].elements.mon:clicked() -- <<< --- ERRORLINE 
     --dosomething 
    end, 
} 

답변

4

는 함수 t을 추가 [X] .elements.mon :.? 클릭() 테이블 선언 후 , 즉 테이블의 닫는 중괄호 뒤에.

t = {} 

t[x] = { 
    some = "data", 

    foo = function() return "bar" end, 

    elements = { -- the class is working 100%, have used it for several projects. 
    mon = class:new(param), 
    tue = class:new(param2), 
    n = class:new(param3), 
    } 
} 


t[x].elements.mon.clicked = function(self) 
     --dosomething 
end 

편집 : 코멘트 기능 t[x].elements.mon:clicked() 실 거예요 작업에서 언급 한 바와 같이

. 함수 선언은 t[x].elements.mon.clicked = function(self)이어야합니다.

콜론을 사용하여 도트 함수를 호출하면 함수의 첫 번째 매개 변수가 self가됩니다. 당신이 c = t[x].elements.mon:clicked(a,b)로 함수를 호출하는 경우 즉, 다음 기능은 t[x].elements.mon.clicked = function(self,a,b)

+0

mhhh, 확실히 더 나은 스타일, 그러나 저를 제공해야한다 '('예상 근처에 '[' – Sempie

+0

curiouse 당신은 그 함수 구문에 괄호 인덱싱 할 수 없습니다; 당신은 먼 길을 가야합니다 :'t [x] .elements.mon.clicked = function (self) ... end' –

+0

맞습니다. – SatheeshJM