276 lines
9.7 KiB
HTML
276 lines
9.7 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html><head>
|
|
|
|
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>wxLua FAQ</title>
|
|
|
|
<meta content="John Labenski" name="author"></head><body>
|
|
<h2><u>wxLua
|
|
2.8.10 - FAQ</u></h2>
|
|
<ol>
|
|
<li><a href="#Why_wxLua">Why wxLua?</a></li>
|
|
<ol>
|
|
<li><a href="#Whats_best_for_my_needs:_wxLua">What's
|
|
best for my needs: wxLua, wxPython, wxSomethingElse?</a></li>
|
|
<li><a href="FAQ.html#Can_I_use_wxLua_as_script_interpreter">Can
|
|
I use wxLua as script interpreter embedded in my own C++ applications?</a></li>
|
|
</ol>
|
|
<li><a href="#How_to_Learn_wxLua">How to learn
|
|
wxLua</a></li>
|
|
<ol>
|
|
<li><a href="#Read_the_wxLua_documentation">Read
|
|
the wxLua documentation</a></li>
|
|
<li><a href="#Read_the_C_wxWidgets_documentation">Read
|
|
the C++ wxWidgets documentation</a></li>
|
|
<li><a href="#Run_and_trace_through_the_samples">Run
|
|
and trace through the samples</a></li>
|
|
</ol>
|
|
<li><a href="#Programming_in_wxLua">Programming
|
|
in wxLua</a></li>
|
|
<ol>
|
|
<li><a href="#wxStrings">wxStrings?</a></li>
|
|
<li><a href="#wxArrayString_and_wxSortedArrayString">wxArrayString
|
|
and wxSortedArrayString?</a></li>
|
|
<li><a href="#wxArrayInt">wxArrayInt?</a></li>
|
|
<li><a href="#When_and_how_should_you_delete_objects">When
|
|
and how should you delete() objects?</a></li>
|
|
<li><a href="#Why_do_the_samples_use_the_function">Why
|
|
do the samples use the function main() and is it special to wxLua?</a></li>
|
|
<li><a href="#Why_are_the_error_messages_for_a_class">Why
|
|
are the arguments shifted +1 for error messages from class member
|
|
function calls?</a></li>
|
|
</ol>
|
|
</ol>
|
|
<hr size="2" width="100%">
|
|
<ol>
|
|
<li>
|
|
<h3><a name="Why_wxLua"></a>Why
|
|
wxLua?</h3>
|
|
</li>
|
|
<ul>
|
|
<li>Because the Lua
|
|
language is easy and "fun" to program in. </li>
|
|
<li>It
|
|
vaguely looks like BASIC or C which many people are familiar with.</li>
|
|
<li>The code is very readable, almost no special
|
|
notation, gotchas, or oddball constructs that require a large
|
|
shift in thinking from BASIC or C.</li>
|
|
<li>Size : The Lua
|
|
interpreter itself is ~100Kb, wxWidgets adds the remaining few Mb.</li>
|
|
<li>Speed : Lua is one of the fastest interpreted languages,
|
|
see
|
|
the Great Computer Language Shootout.</li>
|
|
<li>Again, why
|
|
Lua? See <a href="http://www.lua.org/about.html">http://www.lua.org/about.html</a></li>
|
|
</ul>
|
|
<ol>
|
|
<li>
|
|
<h4><a name="Whats_best_for_my_needs:_wxLua"></a>What's
|
|
best
|
|
for my needs: wxLua, wxPython, wxSomethingElse?</h4>
|
|
</li>
|
|
<ul>
|
|
<li>It depends:
|
|
wxPython has a much larger footprint and greater overhead
|
|
than wxLua, but it does provide more add-ons from the Python standard
|
|
library.</li>
|
|
<li>On the other hand, wxLua is as large as
|
|
the wxWidgets library + ~100Kb for Lua + ~500Kb for the wxLua
|
|
library.</li>
|
|
<li>wxLua can
|
|
be easily interfaced with C++ code making it a powerful
|
|
extension language, which is exactly the intent of its
|
|
designers.</li>
|
|
<li>In conclusion, if you want to write an
|
|
entire application in a
|
|
scripting language and you need things supported by Python which are
|
|
not present in wxLua out-of-the-box, then you should use wxPython.
|
|
Instead, if you want to write applications with little overhead or
|
|
extend your C++ applications, go for wxLua.</li>
|
|
</ul>
|
|
<li>
|
|
<h4><a name="Can_I_use_wxLua_as_script_interpreter"></a>Can
|
|
I
|
|
use wxLua as script interpreter embedded in my own C++ applications?</h4>
|
|
</li>
|
|
<ul>
|
|
<li>Yes!
|
|
That's explained on the wxLua homepage. </li>
|
|
<li>This
|
|
is one of the strong
|
|
points of wxLua: it can be a lightweight, fast interpreter to extend
|
|
your application and let the user customize it... </li>
|
|
<li>You
|
|
may create as
|
|
many wxLua interpreters in a single program as you like.</li>
|
|
</ul>
|
|
</ol>
|
|
<li>
|
|
<h3><a name="How_to_Learn_wxLua"></a>How
|
|
to Learn wxLua</h3>
|
|
</li>
|
|
<ol>
|
|
<li>
|
|
<h4><a name="Read_the_wxLua_documentation"></a>Read
|
|
the wxLua documentation</h4>
|
|
</li>
|
|
<ul>
|
|
<li>wxlua.html is the manual for wxLua that describes the
|
|
Lua language as well as where the wxWidgets C++ are placed in Lua and
|
|
how to use them.</li>
|
|
<li>wxluaref.html is an autogenerated document that can be
|
|
thought of as a reference manual of what wxLua binds from wxWidgets. It
|
|
also has usage notes for the cases where wxLua differs from C++
|
|
wxWidgets.</li>
|
|
<li>binding.html describes how to write your own bindings
|
|
for a C or C++ library, but people who will only write Lua code should
|
|
also read it to be able to interpret the wxluaref.html document.</li>
|
|
</ul>
|
|
<li>
|
|
<h4><a name="Read_the_C_wxWidgets_documentation"></a>Read
|
|
the C++ wxWidgets documentation</h4>
|
|
</li>
|
|
<ul>
|
|
<li>wxLua is mapped very closely to wxWidgets
|
|
which means that descriptions for the functions and values there also
|
|
apply to wxLua. See the wxluaref.html document to verify that this is
|
|
the case and any non typical behavior will be clearly marked.</li>
|
|
<li>See the wxWidgets Wiki for examples of
|
|
code, beginner howtos, and other useful bits of information
|
|
that might be useful.</li>
|
|
<li>See wxPython documentation and their Wiki, but note
|
|
that wxLua follows the C++ notation a little closer than wxPython does.</li>
|
|
</ul>
|
|
<li>
|
|
<h4><a name="Run_and_trace_through_the_samples"></a>Run
|
|
and trace through the samples</h4>
|
|
</li>
|
|
<ul>
|
|
<li>The samples try to show off various classes and their
|
|
usage.</li>
|
|
<li>unittest.wx.lua is used to confirm that wxLua is
|
|
operating properly, however it provides a wealth of information about
|
|
what is allowed in terms of calling functions, casting classes to other
|
|
classes, using virtual functions, and derived functions.</li>
|
|
<li>binding.wx.lua traverses the C structs that store the
|
|
data used for wxLua and it's worth taking the time to browse them to
|
|
see how it all fits together.</li>
|
|
</ul>
|
|
</ol>
|
|
<li>
|
|
<h3><a name="Programming_in_wxLua"></a>Programming
|
|
in wxLua</h3>
|
|
</li>
|
|
<ol>
|
|
<li>
|
|
<h4><a name="wxStrings"></a>wxStrings?</h4>
|
|
</li>
|
|
<ul>
|
|
<li>wxLua uses Lua strings and so all functions that take
|
|
or return a wxString take or return a Lua string.</li>
|
|
<li>However, you can also use a wxString if you really want.</li>
|
|
</ul>
|
|
<li>
|
|
<h4><a name="wxArrayString_and_wxSortedArrayString"></a>wxArrayString
|
|
and wxSortedArrayString?</h4>
|
|
</li>
|
|
<ul>
|
|
<li>All functions that take a wxArrayString or
|
|
wxSortedArrayString can also take a numerically indexed table of
|
|
strings.</li>
|
|
<li>Functions
|
|
that return wxArrayStrings or wxSortedArrayStrings will return a
|
|
wxArrayString or wxSortedArrayString unless specified otherwise in
|
|
wxluaref.html</li>
|
|
</ul>
|
|
<li>
|
|
<h4><a name="wxArrayInt"></a>wxArrayInt?</h4>
|
|
</li>
|
|
<ul>
|
|
<li>All functions that take a wxArrayInt can also take a
|
|
numerically indexed table of numbers.</li>
|
|
<li>Functions that return wxArrayInts will return a
|
|
wxArrayInt unless specified otherwise in wxluaref.html.</li>
|
|
</ul>
|
|
<li>
|
|
<h4><a name="When_and_how_should_you_delete_objects"></a>When
|
|
and how should you delete() objects?</h4>
|
|
</li>
|
|
<ul>
|
|
<li>You should read the subsection "C++ Classes
|
|
CLASS_NAME" of the "Programming in wxLua" section of the wxlua.html
|
|
manual.</li>
|
|
<li>In
|
|
short, all objects that you create that deal with graphics should be
|
|
delete()ed as soon as they're no longer used. Functions that take a
|
|
"const
|
|
wxPen& pen" or any wxObject derived class
|
|
that are passed
|
|
to a function that is const and not a pointer* will make a
|
|
refed
|
|
copy of them and so you may delete them.</li>
|
|
<li>Use
|
|
the function "table = wxlua.GetGCUserdataInfo()" to get a table of
|
|
items that are tracked and either have an active variable pointing to
|
|
them or are waiting to be garbage collected.</li>
|
|
<li>Class objects that have the <i>%delete</i>
|
|
tag in their declaration (see wxluaref.html) will be automatically
|
|
garbage collected or can be delete()ed with the wxLua added function
|
|
for
|
|
the class. There are, of course, exceptions and these occur when you
|
|
pass the object to a function with the <i>%ungc</i> tag on
|
|
the parameter you pass the object to. The ungarbage collect tag
|
|
specifies that the object is now owned by something else and you can no
|
|
longer delete it in wxLua.</li>
|
|
<li>Bottom line - don't worry about delete()ing anything
|
|
except:</li>
|
|
<ul>
|
|
<li>Graphics objects (for MSW really).</li>
|
|
<li>Classes that specifically
|
|
state (in wxluaref.html) that you should delete() them because the
|
|
garbage collector may not do so soon enough.</li>
|
|
<li>Objects that may be very large, like a wxImage(1000,
|
|
1000).</li>
|
|
</ul>
|
|
</ul>
|
|
<li>
|
|
<h4><a name="Why_do_the_samples_use_the_function"></a>Why
|
|
do the samples use the function main() and is it special to wxLua?</h4>
|
|
</li>
|
|
<ul>
|
|
<li>There's nothing special about the function main() other
|
|
than that it's a common name for an entry point into a program.</li>
|
|
<li>It
|
|
is often helpful and a good idea to encapsulate the program
|
|
initialization code within a function so that you can use local
|
|
variables and not pollute the global table with temporary variables
|
|
that won't be needed again.</li>
|
|
<li>Additionally, it allows you to break out of this
|
|
initialization code at any point by putting <span style="font-style: italic;">"do return end"</span>
|
|
inside of the function for debugging, as opposed to wrapping parts you
|
|
don't want using <span style="font-style: italic;">"if
|
|
false then ... end"</span>.</li>
|
|
</ul>
|
|
<li>
|
|
<h4><a name="Why_are_the_error_messages_for_a_class"></a>Why
|
|
are the arguments shifted +1 for error messages from class member
|
|
function calls?</h4>
|
|
</li>
|
|
<ul>
|
|
<li>Because the ':' calling convention is syntaxic sugar
|
|
for putting the 'self' as the first parameter.</li>
|
|
<li><i>s = wx.wxSize(1, 2); s:Set(3, 4)</i>
|
|
is the same as <i>s.Set(s, 3, 4)</i> and the
|
|
first parameter is always the self, therefore <i>s.Set(s,
|
|
"hello", 4)</i> or <i>s:Set("hello", 4)</i> will
|
|
give an error that parameter 2 is not a
|
|
number.</li>
|
|
<li>Unfortunately
|
|
there is no way to tell whether the user
|
|
has used the '.' or ':' calling convention and so the error message
|
|
cannot be tailored for both static and nonstatic member
|
|
functions. Just remember that the first parameter for nonstatic class
|
|
member functions called using the ':' notation is the 'self'.</li>
|
|
</ul>
|
|
</ol>
|
|
</ol>
|
|
</body></html> |