Andre Arpin <[email protected]> wrote:
(02/01/2011 13:24)
>I recommend that use strict while testing and only use necessary global
>variables. You will be amazed at the number of time it will shorten your
>coding cycle.
I set up a copy of Strict.lua (in the base Lua/wxLua directory), and re-ordered
the SpinCtrl script as follows:
require("Strict")
-- Test for correct initial declaration of global variables.
FRAME=wx.wxFrame(wx.NULL,-1,"")
PANEL=wx.wxPanel(FRAME,-1)
SC={}
NT={[0]="Zero","Un","Deux","Trois","Quatre","Cinq","Six","Sept","Huit","Neuf"}
-- Creates a table of text representations to assist user input.
IDS=wx.wxID_HIGHEST+1
-- IDS is 'ID Start', first ID of safe range unused by system.
function Main()
for N=1,4 do local ID=IDS+N
SC[N]=wx.wxSpinCtrl(PANEL,ID,"",wx.wxPoint(N*62-60,2),
-- Physical placement arithmetic done here to keep it simple.
wx.wxSize(60,20),wx.wxSP_ARROW_KEYS+wx.wxTE_PROCESS_ENTER,0,9,N
-- Note two 'styles' to enable arrow keys and direct text entry.
)
SC[N]:Connect(ID,wx.wxEVT_SCROLL_THUMBTRACK,FeedBack)
-- Acts as wxEVT_COMMAND_SPINCTRL_UPDATED once did, ALWAYS signals!
SC[N]:Connect(ID,wx.wxEVT_COMMAND_TEXT_ENTER,FeedBack)
-- Required, as is wxTE_PROCESS_ENTER, to enable direct number entry.
SC[N]:Connect(ID,wx.wxEVT_KILL_FOCUS,NoOp)
-- Prevents de-focus replacing text with lowest preset number value.
FeedBack(N)
end
FRAME:SetTitle("Symbolic SpinCtrl Array")
FRAME:SetSize(258,51) FRAME:Centre() FRAME:Show()
end
function FeedBack(I)
if type(I)=="userdata" then I=I:GetId()-IDS end
-- This test allows the function to be passed an event OR an index.
SC[I]:SetValue(NT[SC[I]:GetValue()])
-- Fetches value, indexes symbolic text to replace it for user display.
end
function NoOp() end
-- Does nothing! Called to prevent unwanted inbuilt event handling.
Main()
This seems to work ok, and is the least disturbed form of my preferred way of
writing. :) I tested Strict on one or two of the sample scripts. Scribble works
ok with a few changes to local for crucial controls, but others were in greater
need of revision. "Minimal.lua" ties a system into nasty knots, and seems to
have some strange structural flaws that appear during initial attempts to
correct it...
I previously thought that "main chunk" meant I could declare globals at the
start of a top level (main) procedure, but it's still a function, the way I do
it, so it seems I have to declare them at the outset. That's ok though, it
helps me to be clear about which variables truly have to be global. I try to
minimise them anyway, I don't like clutter at the top of a file...
I have one question: Is N in the for loop implicitly local? Or is it a global
that Strict failed to notice?
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
wxlua-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wxlua-users