Hello John, thanks for the reply. Here is an example code that does not work (Pasted below and attached the file as well). A function from the main wxlua application calls filterFormActivate which sets up a simple frame with 2 buttons and one static text and associates the button click to SelTaskPress. But when the button is clicked the test() statement gives an error. If that is removed then it cannot recognize the frame varaiable in the wx.wxFrame(frame line after test().
Pleas have a look at it and let me know what is wrong. Thanks, Milind local print = print local wx = wx local bit = bit local GUI = GUI local tostring = tostring module(...) filter = {} function test() print("In test "..tostring(frame)) end local function SelTaskPress(event) test() local frame = wx.wxFrame(frame, wx.wxID_ANY, "Select Task", wx.wxDefaultPosition, wx.wxSize(GUI.initFrameW, GUI.initFrameH), wx.wxDEFAULT_FRAME_STYLE) frame:SetSizer(MainSizer) MainSizer:SetSizeHints(frame) frame:Layout() frame:Show(true) end function filterFormActivate(parent) frame = wx.wxFrame(parent, wx.wxID_ANY, "Filter Form", wx.wxDefaultPosition, wx.wxSize(GUI.initFrameW, GUI.initFrameH), wx.wxDEFAULT_FRAME_STYLE) local MainSizer = wx.wxBoxSizer(wx.wxVERTICAL) MainBook = wx.wxNotebook(frame, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxNB_TOP) TandC = wx.wxPanel(MainBook, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxTAB_TRAVERSAL) local TandCSizer = wx.wxBoxSizer(wx.wxVERTICAL) local TaskSizer = wx.wxBoxSizer(wx.wxHORIZONTAL) SelTaskButton = wx.wxButton(TandC, wx.wxID_ANY, "Select Task", wx.wxDefaultPosition, wx.wxDefaultSize, 0, wx.wxDefaultValidator) TaskSizer:Add(SelTaskButton, 0, bit.bor(wx.wxALL,wx.wxALIGN_CENTER_HORIZONTAL,wx.wxALIGN_CENTER_VERTICAL), 1) FilterTask = wx.wxStaticText(TandC, wx.wxID_ANY, "No Task Selected", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxALIGN_CENTRE) TaskSizer:Add(FilterTask, 1, bit.bor(wx.wxALL,wx.wxALIGN_CENTER_HORIZONTAL,wx.wxALIGN_CENTER_VERTICAL), 1) ClearTaskButton = wx.wxButton(TandC, wx.wxID_ANY, "Clear Task", wx.wxDefaultPosition, wx.wxDefaultSize, 0, wx.wxDefaultValidator) TaskSizer:Add(ClearTaskButton, 0, bit.bor(wx.wxALL,wx.wxALIGN_CENTER_HORIZONTAL,wx.wxALIGN_CENTER_VERTICAL), 1) TandCSizer:Add(TaskSizer, 0, bit.bor(wx.wxALL,wx.wxEXPAND,wx.wxALIGN_CENTER_HORIZONTAL,wx.wxALIGN_CENTER_VERTICAL), 1) TandC:SetSizer(TandCSizer) TandCSizer:SetSizeHints(TandC) MainBook:AddPage(TandC, "T and C") MainSizer:Add(MainBook, 1, bit.bor(wx.wxALL,wx.wxEXPAND,wx.wxALIGN_CENTER_HORIZONTAL,wx.wxALIGN_CENTER_VERTICAL), 1) frame:SetSizer(MainSizer) MainSizer:SetSizeHints(frame) SelTaskButton:Connect(wx.wxEVT_COMMAND_BUTTON_CLICKED, SelTaskPress) ClearTaskButton:Connect(wx.wxEVT_COMMAND_BUTTON_CLICKED, function (event) filter.Tasks = nil FilterTask:SetLabel("No Task Selected") end ) frame:Layout() -- help sizing the windows before being shown frame:Show(true) end On Tue, Feb 14, 2012 at 10:09 PM, Milind Gupta <milind.gupta@...> wrote: > Hi, > I wonder if this is a known issue or something intentional. I have > made a module that creates a frame with some buttons and associates an event > handling function for the button click, the function resides in the module > itself. The frame also is visible in the module. Now when the event handler > is called the event handler function is executed in the global environment > rather than the module environment hence it is not able to see the variables > and functions of the module. > Does this mean event handler functions cannot be in a module? It should be able to work and the environment is saved when the event:Connect() is handled. Upvalues work for sure. Do you have some simple example code of this for me to try. Regards, John
filterform.lua
Description: Binary data
------------------------------------------------------------------------------ Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users