Hello John,
           Sorry for the carelessness. Here is a full set with minimal.lua
which is the main file to run and the module function is called by the
Help->About call back. That is true making test a local function makes it
work although I am not totally clear why but if you press the other button
'Clear Task' it will give an error complaining about filter which again is
not declared local. Actually declaring local  anything in a module only
makes it private. Whether it is declared local or not it always resides in
the module environment. So even if test or filter are not declared local
they should be identified in the module environment. Here is the
Programming in Lua Modules and Packages chapter that clarifies it:

http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf

At least that is how I understood it. So I think it should work without
being declared local. In your previous email you said that the environment
is saved as an upvalue with the execution of Connect. I am not sure how
that would be done since the module itself does not know what environment
 to Global it will be in. Like if you see in minimal I placed it in the
environment newPackage and all my functions tables declared in the module
i.e. test, filter, etc. are in the table newPackage in the global
environment but the module code has no way of knowing that.
    One last point is that unless its an event callback function normal
functions in the module run just fine whether test is local or not. As an
example I just added the test() call as the first line in
filterFormActivate which is a non event function so when the Help-> About
callback calls filterFormActivate, test() just runs fine even though it is
not local but now if you press the Select Task button it will say it could
not find test().


Milind


On Wed, Feb 15, 2012 at 3:14 AM, Milind Gupta <milind.gupta@...> wrote:
> Hello John,
>
>           thanks for the reply. Here is an example code that does not work

Please try to provide enough code to make it run out of the box... I
had to add back GUI.initFrameH and rem out the usage of MainSizer to
make it even possible to run without error.

> (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.

I made the help menu callback function of the minimal.wx.lua sample
call filterform.filterFormActivate(frame).

> 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().

Please always include these errors in the future to help diagnose the
problem.

In order to solve your problem I made test() a local function so that
it will be an upvalue of the Connect() function that calls it. Note
that the 'frame' that is used in the SelTaskPress() function is the
frame from the minimal.wx.lua and not the frame from
filterFormActivate().

To be honest, I have not done too much with modules and require in Lua
since I'm not sure I fully understand its behavior.

I just came across this which clears some things up for me. Note the
sentence "This means that any global functions are not visible by
default, which is why we had to create a local alias to print." This
is probably also why making test() local above fixed it. See also
package.seeall which might be useful to you.
http://www.luafaq.org/#T1.37

Hope this helps,
    John

Attachment: filterform.lua
Description: Binary data

Attachment: minimal.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

Reply via email to