Is evt_tables func copy of func, or referen of func or what?
Posted: Sun Aug 13, 2017 3:42 pm
I am trying to find out about innerworking of how Makebuttons evt_table works as I have trouble doing something.
What I am trying to do is following:
What I am expecting to happen now when i click on this rectangle area is for "Func1" being printed twice: First from the waitevent event activation, and second from "MyObj:LeftMouseDown()" line of code at end of program.
However, what happens is that from event activation it prints "default leftmousedown" and then from the last line the expected "Func1"
Hence, indeed it does copy the new function (func1) on top of the old "myobj.leftmousedown" function, but when the button makes a call, instead of referencing towards the current "MyObj:LeftMouseDown" it is still referring to the old one, i suppose to "Myproto_obj.LeftMouseDown" function.
Is there a way to make makebuttons evt_table to go to the most current myobj.leftmousedown function, or do i have to make two functions to get it done? ie.
What I am trying to do is following:
Code: Select all
myproto_obj = {}
Function myproto_obj:New()
Local d = {}
SetMetaTable(d, self)
self.__index = self
Return(d)
EndFunction
function myproto_obj.LeftMouseDown(msg)
debugprint("default leftmousedown")
endfunction
function myproto_obj:AssignFuncToLeftMouseDown(func)
self.LeftMouseDown = Func
endfunction
function func1 ()
debugprint("func1")
endfunction
MyObj = myproto_obj:New()
MakeButton(Nil, #SIMPLEBUTTON, 100, 100, 1000, 1000, {OnMouseDown=MyObj.LeftMouseDown})
MyObj:AssignFuncToLeftMouseDown(func1)
waitevent()
MyObj:LeftMouseDown()
However, what happens is that from event activation it prints "default leftmousedown" and then from the last line the expected "Func1"
Hence, indeed it does copy the new function (func1) on top of the old "myobj.leftmousedown" function, but when the button makes a call, instead of referencing towards the current "MyObj:LeftMouseDown" it is still referring to the old one, i suppose to "Myproto_obj.LeftMouseDown" function.
Is there a way to make makebuttons evt_table to go to the most current myobj.leftmousedown function, or do i have to make two functions to get it done? ie.
Code: Select all
function myobj.letfmousedown(msg)
myobj.therealleftmousedown(msg)
endfunction
function myobj.therealleftmousedown(msg)
debugprint("default left mouse down")
endfunction
function func1()
debugprint("func1")
endfunction
myobj.therealleftmousedown = func1