### Get wxWidgets Build Settings Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.md Commands to display the build settings for wxWidgets, including the installation prefix, C++ compiler flags, and libraries. ```bash ./wx-config --prefix ``` ```bash ./wx-config --cxxflags ``` ```bash ./wx-config --libs ``` -------------------------------- ### wxLuaState Initialization Step 2: Lua State Setup Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md This code shows the setup of the Lua state within wxLuaState, including ref data creation, registry table manipulation, and print function registration. ```cpp wxLuaState::Create(L, wxLUASTATE_USESTATE); // ... ref data creation, registry table manipulation, print function registration ``` -------------------------------- ### Build and Run wxWidgets Sample Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.md Build and execute a sample program to verify the wxWidgets installation. ```bash cd build_osxud/samples/widgets make ./widgets ``` -------------------------------- ### Install wxWidgets Development Packages on Fedora Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.md List of development packages required for building wxWidgets on Fedora 20. Ensure these are installed before proceeding with the build. ```bash glibc-headers cairo cairo-devel GConf2 GConf2-devel gstreamer gstreamer-devel gstreamer-plugins-base gstreamer-plugins-base-devel gtk2 gtk2-devel libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel libXinerama, libXinerama-devel mesa-libGL, mesa-libGL-devel, mesa-libGLU, mesa-libGLU-devel pango, pango-devel libgnomeprintui libgnomeprintui-devel libnotify libnotify-devel libnotifymm libnotifymm-devel webkitgtk webkitgtk-devel ``` -------------------------------- ### Lua Varargs Handling Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md A comprehensive example demonstrating various ways to handle varargs in Lua, including using the `select` function, the `{...}` syntax to create a table, and `unpack`. ```lua function Varargs(...) local args = {...} print(select("#", ...), #{...}, #args, args[2], unpack({...}, 2, 2)) return args, unpack(args) -- same as return ... end -- prints "4 4 4 20 20" and "table: 0183B820 10 30 5" vals, val1, _, val3 = Varargs(10, 20, 30, 40) print(vals, val1, val3, select("#", Varargs(10, 20, 30, 40))) ``` -------------------------------- ### Lua Function Definition and Call Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md Provides examples of defining a function in Lua using both the `function` keyword and assignment, and then calling it. It also shows how to get the type and memory address of a function. ```lua function f(a, b) return a+b end; print(f, f(1,2), type(f)) ``` ```lua f = function (a, b) return a+b end; print(f, f(1,2), type(f)) ``` -------------------------------- ### io.input Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Sets or gets the default input file. ```APIDOC ## io.input ([file]) ### Description Manages the default input file. Can set a new default input file by name or handle, or return the current default input file. ### Parameters * **file** (string or file handle, optional) - The name of the file or a file handle to set as the default input. ### Returns * (file handle) - The current default input file handle if called without arguments. * (nil) - On failure, raises an error. ``` -------------------------------- ### Lua Table Type Examples Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.html Illustrates table creation, assignment, indexing, and modification. Shows how table assignments are references, not copies. ```lua a = {5}; b = a; b[1] = 6; print(a, b, a[1], b[1], b[2], type(a), type(b)) ``` ```lua t = {} ``` ```lua t = { ["a"] = 5, "first", "second", B = 7 }; print(t.a, t["a"], t[0], t[1], t[2], t.B, t.b, t.c) ``` ```lua t.a = 2; t["a"] = 3; t[10] = 4 ``` ```lua t.a = nil ``` -------------------------------- ### Lua String Type Examples Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.html Demonstrates string assignment, immutability, different quoting styles, multiline strings, and concatenation. ```lua a = "hello"; b = a; b = "hi"; print(a, b, #a, type(a)) ``` ```lua s = "How are 'you'!" ``` ```lua s = 'How\tare "You"!\n' ``` ```lua s = [[How are "'you'"!]] ``` ```lua str1 = "hello"; str2 = "number"; str3 = str1.." "..str2.." "..tostring(2).."!" ``` ```lua str1 = "hello"; str2 = "world"; table.insert(t, str1); table.insert(t, str2); print(table.concat(t)) ``` -------------------------------- ### io.popen Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Starts a program in a separated process and returns a file handle for reading from or writing to the program's standard input/output. ```APIDOC ## io.popen (prog [, mode]) ### Description Starts program `prog` in a separated process and returns a file handle. Use this handle to read data from the program (if `mode` is "r", the default) or to write data to the program (if `mode` is "w"). This function is system dependent and may not be available on all platforms. ### Parameters * `prog` (string) - The program to execute. * `mode` (string, optional) - The mode to open the pipe. "r" for reading from the program, "w" for writing to the program. Defaults to "r". ### Returns * (file handle) - A file handle for communication with the program. ``` -------------------------------- ### wxLuaState Initialization Step 3: Binding Registration Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md This code snippet illustrates the registration of wxLua bindings by initializing and installing derived wxLuaBinding classes. ```cpp wxLuaState::RegisterBindings(); // ... wxLuaBinding_XXX_init() calls ``` -------------------------------- ### Setup wxLua Compiler Definitions Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/CMakeLists.txt This macro must be called in any CMakeLists.txt that uses wxLua headers to ensure correct compiler preprocessor definitions are applied. ```cmake macro(SETUP_wxLua) # These have to be defined so that the macros in modules/wxbind/include/wxbinddefs.h work add_definitions(${wxLua_CXX_DEFINITIONS}) endmacro() ``` -------------------------------- ### Basic wxLua Module Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md Demonstrates the minimal code required to show a wxFrame when using wxLua as a module. The `MainLoop()` call is essential for the frame to be displayed and interactive. ```lua require("wx") f = wx.wxFrame(wx.NULL, -1, "Title") f:Show() wx.wxGetApp():MainLoop() ``` -------------------------------- ### Lua Table Constructor Expansion Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Shows the expanded form of the table constructor example, illustrating how different field initializations are translated into explicit table assignments. ```lua do local t = {} t[f(1)] = g t[1] = "x" -- 1st exp t[2] = "y" -- 2nd exp t.x = 1 -- t["x"] = 1 t[3] = f(x) -- 3rd exp t[30] = 23 t[4] = 45 -- 4th exp a = t end ``` -------------------------------- ### Lua Coroutine Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Demonstrates the creation, resumption, and yielding of coroutines using `coroutine.create` and `coroutine.resume`. Shows how values are passed between the main thread and the coroutine, and how errors are handled. ```lua function foo (a) print("foo", a) return coroutine.yield(2*a) end co = coroutine.create(function (a,b) print("co-body", a, b) local r = foo(a+1) print("co-body", r) local r, s = coroutine.yield(a+b, a-b) print("co-body", r, s) return b, "end" end) print("main", coroutine.resume(co, 1, 10)) print("main", coroutine.resume(co, "r")) print("main", coroutine.resume(co, "x", "y")) print("main", coroutine.resume(co, "x", "y")) ``` -------------------------------- ### Lua string.rep example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Concatenates a given string a specified number of times. ```lua string.rep("abc", 3) ``` -------------------------------- ### Lua Coroutine Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Demonstrates the creation, execution, yielding, and resumption of Lua coroutines using `coroutine.create` and `coroutine.resume`. Shows how values are passed between the main thread and the coroutine. ```lua function foo (a) print("foo", a) return coroutine.yield(2*a) end co = coroutine.create(function (a,b) print("co-body", a, b) local r = foo(a+1) print("co-body", r) local r, s = coroutine.yield(a+b, a-b) print("co-body", r, s) return b, "end" end) print("main", coroutine.resume(co, 1, 10)) print("main", coroutine.resume(co, "r")) print("main", coroutine.resume(co, "x", "y")) print("main", coroutine.resume(co, "x", "y")) ``` -------------------------------- ### Lua Vararg Function Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.html Demonstrates defining and using functions with a variable number of arguments (varargs) in Lua. Shows how to count arguments and convert them to a table. ```lua -- Print the keys in table t that have the given values. function PrintKeys(t, values, cmp_case) -- use nested functions for repetitive code or to simplify code local function cmp_values(a, b) if cmp_case then -- can use upvalue variables return a == b else return string.lower(a) == string.lower(b) end end local function find_key(t, val) for k,v in pairs(t) do if cmp_values(val, v) then return k end end end for i = 1, #values do print(find_key(t, values[i]), values[i]) end end data = {a1 = "a2", b1 = "b2", c1 = "c2"} -- prints "a1 a2", "b1 b2", "nil C2" PrintKeys(data, {"a2", "b2", "C2"}, true) -- Varargs example demonstrating the different ways to handle them. ``` -------------------------------- ### Lua Lexical Scoping Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Demonstrates lexical scoping rules with nested blocks and local variables. ```lua x = 10 -- global variable do -- new block local x = x -- new 'x', with value 10 print(x) --> 10 x = x+1 do -- another block local x = x+1 -- another 'x' print(x) --> 12 end print(x) --> 11 end print(x) --> 10 (the global one) ``` -------------------------------- ### Checkout wxWidgets Trunk Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.md Use this command to get the latest trunk version of wxWidgets (e.g., 2.9.x). ```bash svn checkout http://svn.wxwidgets.org/svn/wx/wxWidgets/trunk wxWidgets-trunk ``` -------------------------------- ### Lua Logical Operators Examples Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Demonstrates the short-circuit evaluation and return values of Lua's 'and' and 'or' logical operators. ```lua 10 or 20 -- --> 10 10 or error() -- --> 10 nil or "a" -- --> "a" nil and 10 -- --> nil false and error() -- --> false false and nil -- --> false false or nil -- --> nil 10 and 20 -- --> 20 ``` -------------------------------- ### Initialize wxlua Core Library in C++ Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.html This specific initialization function is for the core wxlua library. It should be called during application setup before any wxLuaState instances are created. ```cpp extern bool wxLuaBinding_wxlua_init(); ``` -------------------------------- ### Lua Varargs Function Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.html Demonstrates the use of varargs in Lua functions, including how to access and unpack them. Note the output of the print statements. ```lua function Varargs(...) local args = {...} print(select("#", ...), #{...}, #args, args[2], unpack({...}, 2, 2)) return args, unpack(args) -- same as return ... end -- prints "4 4 4 20 20" and "table: 0183B820 10 30 5" vals, val1, _, val3 = Varargs(10, 20, 30, 40) print(vals, val1, val3, select("#", Varargs(10, 20, 30, 40))) ``` -------------------------------- ### Lua nil Type Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.html Demonstrates the nil type, its assignment, and how unassigned variables are nil. Also shows using 'or' for inline nil alternatives. ```lua a = nil; local b; print(a, b, type(a), type(b)) ``` ```lua print(tonumber("a"), tonumber("a") or 1) ``` -------------------------------- ### Lua Closures and Upvalues Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Illustrates how closures capture external local variables (upvalues) and how each closure gets its own 'y' but shares 'x'. ```lua a = {} local x = 20 for i=1,10 do local y = 0 a[i] = function () y=y+1; return x+y end end ``` -------------------------------- ### Build and Run wxWidgets Sample Program Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.md Steps to build and execute a sample wxWidgets program (e.g., 'widgets') as a verification step after compilation. ```bash cd build_gtk2ud/samples/widgets make ./widgets ``` -------------------------------- ### Lua __newindex Metamethod Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Handles table assignment when a key is not present in the table. It prioritizes raw assignment if the key exists, otherwise it uses the __newindex metamethod. ```lua function settable_event (table, key, value) local h if type(table) == "table" then local v = rawget(table, key) -- if key is present, do raw assignment if v ~= nil then rawset(table, key, value); return end h = metatable(table).__newindex if h == nil then rawset(table, key, value); return end else h = metatable(table).__newindex if h == nil then error(···) end end if type(h) == "function" then h(table, key,value) -- call the handler else h[key] = value -- or repeat operation on it end end ``` -------------------------------- ### wxLuaState Initialization Step 1: Lua State Creation Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md This code demonstrates the initial steps in creating a Lua state, including opening standard libraries and the bit32 library. ```cpp lua_open(); lual_openlibs(L); luaopen_bit(L); ``` -------------------------------- ### Get Local Variable Information Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Retrieves information about a local variable within a specific activation record. Pushes the variable's value onto the stack and returns its name. Variable names starting with '(' are internal. ```c const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n); ``` -------------------------------- ### Running wxLua Samples from Command Line Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md Execute wxLua sample programs directly from the command line using `wxlua.exe` or `wxluafreeze.exe`. Ensure the sample file has the `.wx.lua` extension. ```bash wxlua.exe sample.wx.lua ``` ```bash wxluafreeze.exe sample.wx.lua ``` -------------------------------- ### wxLua: Constructing and Copying wxWidgets Objects Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.html Demonstrates how to instantiate wxWidgets objects in wxLua using their class names and how to create a copy of an existing object. ```lua pt = wx.wxPoint(1, 2); pt2 = wx.wxPoint(pt) ``` -------------------------------- ### Lua Non-Tail Call Examples Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Provides examples of function calls that are not tail calls, illustrating scenarios where stack entries are not reused or results are modified. ```lua return (f(x)) -- results adjusted to 1 return 2 * f(x) return x, f(x) -- additional results f(x); return -- results discarded return x or f(x) -- results adjusted to 1 ``` -------------------------------- ### Lua Number Type Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md Illustrates the 'number' type, which uses double-precision floating-point values. Includes examples of scientific notation and the use of the 'math' library. ```lua a = 1; b = 3.14; print(a, b, type(a), type(b)) ``` ```lua n = (1E1 * 3.14 * math.sin(1) / 4)*math.pow(2.5e-1, 4) ``` -------------------------------- ### Running wxLua Samples in wxLua IDE Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md Open and run wxLua sample programs using the `wxlua.exe` or `wxluaedit.exe` applications. Use the 'Run' menu item or the 'play' button in `wxluaedit.exe`. ```lua -- In wxlua.exe: Choose menu item 'Run' -- In wxluaedit.exe: Select menu 'wxLua->Run' or press 'play' button ``` -------------------------------- ### Get Function Information with lua_getinfo Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Retrieves detailed information about a function or function invocation. Use 'S' to get source, line numbers, and function type. Use 'n' for name information. 'l' gets the current line, 'u' for number of upvalues, 'f' pushes the function, and 'L' pushes a table of valid lines. ```c int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); ``` ```c lua_Debug ar; lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* get global 'f' */ lua_getinfo(L, ">S", &ar); printf("%d\n", ar.linedefined); ``` -------------------------------- ### Resume Coroutine Execution Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Starts or resumes the execution of a coroutine. Returns LUA_YIELD if the coroutine yields, 0 on successful completion, or an error code. Handles starting a coroutine with initial arguments and resuming after a yield. ```c int lua_resume (lua_State *L, int narg); ``` -------------------------------- ### Lua Table Constructor Example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Demonstrates initializing a table with various field types, including explicit keys, string keys, numerical indices, and explicit numerical indices. ```lua a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 } ``` -------------------------------- ### Example Lua C Function: Average and Sum Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html An example C function that calculates the average and sum of numerical arguments passed from Lua. It demonstrates stack manipulation, type checking, and returning multiple values. ```c static int foo (lua_State *L) { int n = lua_gettop(L); /* number of arguments */ lua_Number sum = 0; int i; for (i = 1; i <= n; i++) { if (!lua_isnumber(L, i)) { lua_pushstring(L, "incorrect argument"); lua_error(L); } sum += lua_tonumber(L, i); } lua_pushnumber(L, sum/n); /* first result */ lua_pushnumber(L, sum); /* second result */ return 2; /* number of results */ } ``` -------------------------------- ### io.output Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Sets or gets the default output file. ```APIDOC ## io.output ([file]) ### Description Manages the default output file. Can set a new default output file by name or handle, or return the current default output file. ### Parameters * **file** (string or file handle, optional) - The name of the file or a file handle to set as the default output. ### Returns * (file handle) - The current default output file handle if called without arguments. * (nil) - On failure, raises an error. ``` -------------------------------- ### Lua Table Initialization and Access Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md Demonstrates creating an empty table, assigning values using different syntaxes, and accessing elements. Elements that do not exist return nil. Values can be cleared by setting them to nil. ```lua t = {} -- You must declare a variable as a table before using its indexes. t = { ["a"] = 5, "first", "second", B = 7 }; print(t.a, t["a"], t[0], t[1], t[2], t.B, t.b, t.c) -- Set values as : t.a = 2; t["a"] = 3; t[10] = 4 -- Clear values by setting them to nil, e.g. t.a = nil ``` -------------------------------- ### string.sub Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Returns the substring of `s` that starts at `i` and continues until `j`. ```APIDOC ## string.sub (s, i [, j]) ### Description Returns the substring of `s` that starts at `i` and continues until `j`; `i` and `j` can be negative. If `j` is absent, then it is assumed to be equal to -1 (which is the same as the string length). ### Parameters - **s** (string) - The input string. - **i** (number) - The starting index. - **j** (number, optional) - The ending index. ### Return Value - **string**: The substring. ### Example ```lua print(string.sub("hello world", 1, 5)) -- Output: hello print(string.sub("hello world", -5)) -- Output: world print(string.sub("hello world", 7)) -- Output: world ``` ``` -------------------------------- ### lua_resume Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Starts or resumes a coroutine, returning its status. ```APIDOC ## lua_resume ### Description Starts and resumes a coroutine in a given thread. To start a coroutine, you first create a new thread (see [`lua_newthread`](#lua_newthread)); then you push onto its stack the main function plus any arguments; then you call [`lua_resume`](#lua_resume), with `narg` being the number of arguments. This call returns when the coroutine suspends or finishes its execution. When it returns, the stack contains all values passed to [`lua_yield`](#lua_yield), or all values returned by the body function. [`lua_resume`](#lua_resume) returns [`LUA_YIELD`](#pdf-LUA_YIELD) if the coroutine yields, 0 if the coroutine finishes its execution without errors, or an error code in case of errors (see [`lua_pcall`](#lua_pcall)). In case of errors, the stack is not unwound, so you can use the debug API over it. The error message is on the top of the stack. To restart a coroutine, you put on its stack only the values to be passed as results from `yield`, and then call [`lua_resume`](#lua_resume). ### Signature `int lua_resume (lua_State *L, int narg);` ``` -------------------------------- ### Lua string.reverse example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Reverses the order of characters in a string. ```lua string.reverse("hello") ``` -------------------------------- ### Lua string.lower example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Converts all uppercase letters in a string to lowercase. ```lua string.lower("Hello World") ``` -------------------------------- ### Configure wxWidgets Build on OSX Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.md Use this script to configure a Unicode, Debug build of wxWidgets on OSX with GCC. Adjust options as needed. ```bash ../configure --prefix=$PWD \ --with-osx-cocoa \ --enable-unicode \ --disable-shared \ --enable-optimise=no \ --enable-mem_tracing=no \ --enable-profile=no \ --with-dmalloc=no \ \ --enable-debug \ --enable-debug_flag \ --enable-debug_info \ --enable-debug_gdb \ --enable-debug_cntxt \ \ --with-opengl \ --enable-sound \ --enable-mediactrl \ --enable-graphics_ctx \ --enable-controls \ --enable-dataviewctrl 2>&1 | tee configure-osx2ud.log ``` -------------------------------- ### Lua Table Constructor Initialization Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Demonstrates creating a table and initializing fields using various syntaxes, including named fields, array-like elements, and explicit key-value pairs. Fields are assigned sequentially to numerical indices starting from 1 unless explicitly specified. ```lua a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 } ``` ```lua do local t = {} t[f(1)] = g t[1] = "x" t[2] = "y" t.x = 1 t[3] = f(x) t[30] = 23 t[4] = 45 a = t end ``` -------------------------------- ### Lua string.len example Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Calculates the length of a string, correctly counting embedded null characters. ```lua string.len("a\000bc\000") ``` -------------------------------- ### Lua Initialization with Environment Variables Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html How Lua initializes based on environment variables LUA_INIT_5_2 or LUA_INIT. This allows pre-loading scripts or strings before main execution. ```bash LUA_INIT_5_2 ``` ```bash LUA_INIT ``` -------------------------------- ### file:seek Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Sets and gets the file position. Returns the final position or nil on error. ```APIDOC ## file:seek ### Description Sets and gets the file position, measured from the beginning of the file, to the position given by `offset` plus a base specified by the string `whence`, as follows: * **"set":** base is position 0 (beginning of the file); * **"cur":** base is current position; * **"end":** base is end of file; In case of success, function `seek` returns the final file position, measured in bytes from the beginning of the file. If this function fails, it returns **nil**, plus a string describing the error. The default value for `whence` is `"cur"`, and for `offset` is 0. Therefore, the call `file:seek()` returns the current file position, without changing it; the call `file:seek("set")` sets the position to the beginning of the file (and returns 0); and the call `file:seek("end")` sets the position to the end of the file, and returns its size. ### Method `file:seek ([whence] [, offset])` ``` -------------------------------- ### Checkout wxWidgets 2.8 Branch Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.md Use this command to get the latest 2.8.x version of wxWidgets. ```bash svn checkout http://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH wxWidgets-2.8 ``` -------------------------------- ### Substring Extraction with string.sub Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Extracts a portion of a string based on start and end indices, which can be negative. ```lua string.sub("hello world", 1, 5) ``` ```lua string.sub("hello world", -5) ``` ```lua string.sub("hello world", 1, -1) ``` -------------------------------- ### Using wxLua as a Module Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.html Demonstrates the basic structure for using wxLua as a module in a Lua script. Ensure 'require("wx")' is called to load bindings and 'wx.wxGetApp():MainLoop()' to start the event loop. ```lua require("wx") f = wx.wxFrame(wx.NULL, -1, "Title") f:Show() wx.wxGetApp():MainLoop() ``` -------------------------------- ### Lua Upvalue Manipulation Functions Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/contents.html Functions for managing upvalues, including getting their IDs, indices, and joining them. ```APIDOC ## lua_upvalueid ### Description Returns a unique identifier for an upvalue. ### Method C Function ### Parameters - **L** (lua_State*) - The Lua state. - **funcindex** (int) - The index of the function in the stack. - **n** (int) - The index of the upvalue (0-based). ### Return Value (void*) - A unique identifier for the upvalue. ``` ```APIDOC ## lua_upvalueindex ### Description Converts an upvalue index to a stack index. ### Method C Function ### Parameters - **i** (int) - The 1-based index of the upvalue. ### Return Value (int) - The corresponding stack index. ``` ```APIDOC ## lua_upvaluejoin ### Description Joins two upvalues, making them refer to the same value. ### Method C Function ### Parameters - **L** (lua_State*) - The Lua state. - **funcindex** (int) - The index of the function in the stack. - **n1** (int) - The index of the first upvalue. - **n2** (int) - The index of the second upvalue. ``` -------------------------------- ### lua_createtable Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Creates a new empty table and pushes it onto the stack. 'narr' and 'nrec' provide hints for pre-allocating table capacity. ```APIDOC ## lua_createtable ### Description Creates a new empty table and pushes it onto the stack. 'narr' and 'nrec' provide hints for pre-allocating table capacity. ### Parameters #### Path Parameters - **L** (lua_State *) - The Lua state. - **narr** (int) - Hint for the number of elements in the array part. - **nrec** (int) - Hint for the number of elements in the record part. ### Returns - **void**: This function does not return a value. ``` -------------------------------- ### coroutine.resume Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Starts or continues the execution of a coroutine. Returns true on success, or false and an error message on failure. ```APIDOC ## coroutine.resume (co [, val1, ···]) ### Description Starts or continues the execution of coroutine `co`. The first time you resume a coroutine, it starts running its body. The values `val1`, ... are passed as the arguments to the body function. If the coroutine has yielded, `resume` restarts it; the values `val1`, ... are passed as the results from the yield. If the coroutine runs without any errors, `resume` returns **true** plus any values passed to `yield` (if the coroutine yields) or any values returned by the body function (if the coroutine terminates). If there is any error, `resume` returns **false** plus the error message. ### Parameters #### Path Parameters - **co** (thread) - The coroutine to resume. - **val1, ···** (any) - Optional arguments to pass to the coroutine. ``` -------------------------------- ### Build Static Libraries with MinGW Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.md Use this command to build static libraries with MinGW. Specify SHARED=0, UNICODE=1, and BUILD=[debug,release]. ```bash mingw32-make.exe -f makefile.gcc SHARED=0 UNICODE=1 BUILD=[debug,release] ``` -------------------------------- ### luaL_traceback Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Creates and pushes a traceback of the stack. Allows prepending a message and specifying the starting level for the traceback. ```APIDOC ## luaL_traceback ### Description Creates and pushes a traceback of the stack `L1`. If `msg` is not `NULL` it is appended at the beginning of the traceback. The `level` parameter tells at which level to start the traceback. ### Signature `void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level);` ``` -------------------------------- ### module Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Creates or retrieves a module table, setting its name, environment, and package information. ```APIDOC ## module (name [, ···]) ### Description Creates a module. If there is a table in `package.loaded[name]`, this table is the module. Otherwise, if there is a global table `t` with the given name, this table is the module. Otherwise creates a new table `t` and sets it as the value of the global `name` and the value of `package.loaded[name]`. This function also initializes `t._NAME` with the given name, `t._M` with the module (`t` itself), and `t._PACKAGE` with the package name (the full module name minus last component; see below). Finally, `module` sets `t` as the new environment of the current function and the new value of `package.loaded[name]`, so that `require` returns `t`. This function can receive optional _options_ after the module name, where each option is a function to be applied over the module. ### Parameters - **name** (string) - The name of the module. - **···** (function, optional) - Optional functions to be applied to the module table. ### Behavior - If `package.loaded[name]` exists, it is used as the module. - Otherwise, if a global table `name` exists, it is used as the module. - Otherwise, a new table is created for the module and assigned to the global `name` and `package.loaded[name]`. - Initializes `_NAME`, `_M`, and `_PACKAGE` fields in the module table. - Sets the module table as the new environment for the current function. - If `name` is a compound name (e.g., `a.b.c`), intermediate tables are created or reused. ``` -------------------------------- ### luaL_loadfile Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Loads a file as a Lua chunk. It handles standard input and ignores the first line if it starts with '#'. ```APIDOC ## luaL_loadfile ### Description Loads a file as a Lua chunk. This function uses [`lua_load`](#lua_load) to load the chunk in the file named `filename`. If `filename` is `NULL`, then it loads from the standard input. The first line in the file is ignored if it starts with a `#`. This function returns the same results as [`lua_load`](#lua_load), but it has an extra error code `LUA_ERRFILE` if it cannot open/read the file. As [`lua_load`](#lua_load), this function only loads the chunk; it does not run it. ### Signature `int luaL_loadfile (lua_State *L, const char *filename);` ``` -------------------------------- ### debug.traceback Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Returns a string representing the call stack traceback, optionally starting from a specified level and with a prepended message. ```APIDOC ## debug.traceback ### Description If `message` is present but is neither a string nor **nil**, this function returns `message` without further processing. Otherwise, it returns a string with a traceback of the call stack. An optional `message` string is appended at the beginning of the traceback. An optional `level` number tells at which level to start the traceback (default is 1, the function calling `traceback`). ``` -------------------------------- ### Build wxLua with MinGW using make Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.html After generating build files with CMake, use mingw32-make.exe to build wxLua. Running without parameters builds all targets. ```shell mingw32-make.exe ``` -------------------------------- ### coroutine.resume Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Starts or continues the execution of a coroutine. Returns true and results on success, or false and an error message on failure. ```APIDOC ## coroutine.resume (co [, val1, ···]) ### Description Starts or continues the execution of coroutine `co`. The first time you resume a coroutine, it starts running its body. The values `val1`, ··· are passed as the arguments to the body function. If the coroutine has yielded, `resume` restarts it; the values `val1`, ··· are passed as the results from the yield. If the coroutine runs without any errors, `resume` returns **true** plus any values passed to `yield` (if the coroutine yields) or any values returned by the body function (if the coroutine terminates). If there is any error, `resume` returns **false** plus the error message. ### Parameters - **co** (thread) - The coroutine to resume. - **val1, ···** (any, optional) - Values to be passed as arguments to the coroutine's body or as results from `yield`. ### Returns - **boolean**: `true` if the coroutine executed successfully, `false` if an error occurred. - **any**: If `true`, returns values passed to `yield` or returned by the coroutine's body. If `false`, returns the error message. ``` -------------------------------- ### Configure wxWidgets Build Script Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.html This script configures the wxWidgets build for a GTK2, Unicode, Debug setup. It enables various features and logs the configuration output. Adjust options as needed for your specific requirements. ```bash ../configure --prefix=$PWD \ --enable-gtk2 \ --enable-unicode \ --enable-shared \ --enable-optimise=no \ --enable-mem_tracing=no \ --enable-profile=no \ --with-dmalloc=no \ \ --enable-debug \ --enable-debug_flag \ --enable-debug_info \ --enable-debug_gdb \ --enable-debug_cntxt \ \ --with-sdl \ --with-gnomeprint \ \ --with-opengl \ --enable-sound \ --enable-mediactrl \ --enable-graphics_ctx \ --enable-controls \ --enable-dataviewctrl 2>&1 | tee configure-gtk2ud.log ``` -------------------------------- ### Build wxWidgets Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/install.md Command to compile wxWidgets using make. Adjust the '-j' flag to match your system's processor count for faster compilation. ```bash make -j4 ``` -------------------------------- ### Lua Numerical Constants Examples Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.2/doc/manual.html Illustrates valid numerical constants in Lua, including decimal, hexadecimal, and scientific notation. ```lua 3 3.0 3.1416 314.16e-2 0.31416E1 ``` ```lua 0xff 0x0.1E 0xA23p-4 0X1.921FB54442D18P+1 ``` -------------------------------- ### wxSize Member Function and Property Access Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md Demonstrates creating a wxSize object, modifying its width using the ':' convention for member functions, and setting its height using '.' notation with the object passed as the first argument. It also shows retrieving width and height using both ':' and '.' conventions. ```lua size = wx.wxSize(1, 2); size:SetWidth(10); size.SetHeight(size, 11); print(size:GetWidth(), size.GetHeight(size)) ``` -------------------------------- ### Lua: Get Binary Operation Handler Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Illustrates how Lua selects a handler for binary operations by checking the metatables of both operands. ```lua function getbinhandler (op1, op2, event) return metatable(op1)[event] or metatable(op2)[event] end ``` -------------------------------- ### Lua Function Definition Syntax Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/modules/lua-5.1/doc/manual.html Illustrates the basic syntax for defining functions in Lua. ```lua function f () _body_ end ``` -------------------------------- ### Accessing Defines and Variables Source: https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.html Demonstrates how to access C++ #defines and global numerical variables exposed in wxLua. ```APIDOC ## Accessing Defines and Variables ### Description Numerical defines and global variables from C++ are accessible as properties of the `wx` table in Lua. ### Usage - `#define NUMBER_DEFINE VALUE` is accessed as `wx.NUMBER_DEFINE`. - `[int, double, etc] NUMBER_VARIABLE;` is accessed as `wx.NUMBER_VARIABLE`. ### Example ```lua -- Accessing a define local anyId = wx.wxID_ANY -- Accessing a global variable local invalidOffset = wx.wxInvalidOffset ``` ```