Dear all:I have just encountered this kind of issue,using wxlua in Lua for windows (LuaForWindows_v5.1.4-36).I extend class using the method mentioned in "Extending classes" of http://wxlua.sourceforge.net/docs/wxlua.html. In the attatchment of file "veryminimal.wx.wlua",I wrote a coroutine function in a button handler.
""" function mainframe_on_button(self,event) print("---outside coroutine") print(self) print(self.button) print(self.textEntry)
local function test_co_func() print("---inside coroutine") print(self) print(self.button) print(self.textEntry) end self.co = coroutine.create(test_co_func) local r,e = coroutine.resume(self.co) if (r == false) then print(r,e) end end """ And the output is: """ ---outside coroutine userdata: 016454F8 [wxFrame(01645138, 186)] userdata: 016462F0 [wxButton(01646160, 109)] userdata: 01645D98 [wxTextCtrl(01645BA0, 337)] ---inside coroutine userdata: 016454F8 [wxFrame(01645138, 186)] button textEntry """ Why can not access the right value in coroutine ? Thanks!
----------------------------------------------------------------------------- -- Name: minimal.wx.lua -- Purpose: 'Minimal' wxLua sample -- Author: J Winwood -- Modified by: -- Created: 16/11/2001 -- RCS-ID: $Id: veryminimal.wx.lua,v 1.7 2008/01/22 04:45:39 jrl1 Exp $ -- Copyright: (c) 2001 J Winwood. All rights reserved. -- Licence: wxWidgets licence ----------------------------------------------------------------------------- -- Load the wxLua module, does nothing if running from wxLua, wxLuaFreeze, or wxLuaEdit local print = print package.cpath = package.cpath..";./?.dll;./?.so;../lib/?.so;../lib/vc_dll/?.dll;../lib/bcc_dll/?.dll;../lib/mingw_dll/?.dll;" require("wx") frame = nil function mainframe_on_button(self,event) print("---outside coroutine") print(self) print(self.button) print(self.textEntry) local function test_co_func() print("---inside coroutine") print(self) print(self.button) print(self.textEntry) end self.co = coroutine.create(test_co_func) local r,e = coroutine.resume(self.co) if (r == false) then print(r,e) end end function main() -- create the frame window local frame = wx.wxFrame( wx.NULL, wx.wxID_ANY, "wxLua Very Minimal Demo", wx.wxDefaultPosition, wx.wxSize(450, 450), wx.wxDEFAULT_FRAME_STYLE ) -- Create two controls (note that their parents are the _frame_ (not the sizer)) local textEntry = wx.wxTextCtrl(frame, wx.wxID_ANY, "Enter URL"); local button = wx.wxButton(frame, wx.wxID_ANY, "test") -- Put them in a vertical sizer, with ratio 3 units for the text entry, 5 for button -- and padding of 6 pixels. sizerTop = wx.wxBoxSizer(wx.wxVERTICAL) sizerTop:Add(textEntry, 3, wx.wxGROW + wx.wxALL, 6) sizerTop:Add(button, 5, wx.wxGROW + wx.wxALL, 6) -- Set up the frame to use that sizer to move/resize its children controls frame:SetAutoLayout(true) frame:SetSizer(sizerTop) frame.textEntry = textEntry frame.button = button frame.button:Connect(wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event) mainframe_on_button(frame,event) end) -- show the frame window frame:Show(true) end main() -- Call wx.wxGetApp():MainLoop() last to start the wxWidgets event loop, -- otherwise the wxLua program will exit immediately. -- Does nothing if running from wxLua, wxLuaFreeze, or wxLuaEdit since the -- MainLoop is already running or will be started by the C++ program. wx.wxGetApp():MainLoop()
------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users