/docs/wxlua/doxygen/html/wxlstate_8cpp_source.html
HTML | 4250 lines | 4249 code | 0 blank | 1 comment | 0 complexity | 9800ca9bd30bf697b6a3754baaf54733 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.0, CC-BY-SA-3.0, ISC, LGPL-2.1, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <title>wxLua: /mnt/share/devel/lua/wxLua/modules/wxlua/src/wxlstate.cpp Source File</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <link href="doxygen.css" rel="stylesheet" type="text/css"/>
- </head>
- <body>
- <!-- Generated by Doxygen 1.6.3 -->
- <div class="navigation" id="top">
- <div class="tabs">
- <ul>
- <li><a href="main.html"><span>Main Page</span></a></li>
- <li><a href="annotated.html"><span>Classes</span></a></li>
- <li class="current"><a href="files.html"><span>Files</span></a></li>
- <li><a href="dirs.html"><span>Directories</span></a></li>
- </ul>
- </div>
- <div class="tabs">
- <ul>
- <li><a href="files.html"><span>File List</span></a></li>
- <li><a href="globals.html"><span>File Members</span></a></li>
- </ul>
- </div>
- <div class="navpath"><a class="el" href="dir_15d5a205ad383328522db6a6be296af1.html">modules</a> » <a class="el" href="dir_b59b58daa92d206701e75411b2cef894.html">wxlua</a> » <a class="el" href="dir_83fe9eb5cda99cf12108735ec0aac68a.html">src</a>
- </div>
- </div>
- <div class="contents">
- <h1>wxlstate.cpp</h1><a href="wxlstate_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/////////////////////////////////////////////////////////////////////////////</span>
- <a name="l00002"></a>00002 <span class="comment"></span><span class="comment">// Name: wxlstate.cpp</span>
- <a name="l00003"></a>00003 <span class="comment">// Purpose: wxLuaState, a wxWidgets interface to Lua</span>
- <a name="l00004"></a>00004 <span class="comment">// Author: Ray Gilbert, John Labenski, J Winwood (Reuben Thomas for bitlib at bottom)</span>
- <a name="l00005"></a>00005 <span class="comment">// Created: 14/11/2001</span>
- <a name="l00006"></a>00006 <span class="comment">// Copyright: (c) 2001-2002 Lomtick Software. All rights reserved.</span>
- <a name="l00007"></a>00007 <span class="comment">// Licence: wxWidgets licence</span><span class="comment"></span>
- <a name="l00008"></a>00008 <span class="comment">/////////////////////////////////////////////////////////////////////////////</span>
- <a name="l00009"></a>00009 <span class="comment"></span>
- <a name="l00010"></a>00010 <span class="comment">// For compilers that support precompilation, includes "wx/wx.h"</span>
- <a name="l00011"></a>00011 <span class="preprocessor">#include "wx/wxprec.h"</span>
- <a name="l00012"></a>00012
- <a name="l00013"></a>00013 <span class="preprocessor">#ifdef __BORLANDC__</span>
- <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor"> #pragma hdrstop</span>
- <a name="l00015"></a>00015 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
- <a name="l00016"></a>00016 <span class="preprocessor"></span>
- <a name="l00017"></a>00017 <span class="comment">// for all others, include the necessary headers</span>
- <a name="l00018"></a>00018 <span class="preprocessor">#ifndef WX_PRECOMP</span>
- <a name="l00019"></a>00019 <span class="preprocessor"></span><span class="preprocessor"> #include "wx/wx.h"</span>
- <a name="l00020"></a>00020 <span class="preprocessor">#endif</span>
- <a name="l00021"></a>00021 <span class="preprocessor"></span>
- <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="wxlstate_8h.html">wxlua/include/wxlstate.h</a>"</span>
- <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="wxlcallb_8h.html">wxlua/include/wxlcallb.h</a>"</span>
- <a name="l00024"></a>00024 <span class="preprocessor">#include "wx/tokenzr.h"</span>
- <a name="l00025"></a>00025
- <a name="l00026"></a>00026 <span class="comment">//#include "wxluadebug/include/wxldebug.h" // for debugging only</span>
- <a name="l00027"></a>00027
- <a name="l00028"></a><a class="code" href="wxlstate_8cpp.html#a0ef6804bd2cb63f4fa705727f8871cbd">00028</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a0ef6804bd2cb63f4fa705727f8871cbd">wxlua_lreg_types_key</a> = <span class="stringliteral">"wxLua metatable class types"</span>;
- <a name="l00029"></a><a class="code" href="wxlstate_8cpp.html#ac4ac0a3575fafde31e659ced85f69c4d">00029</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#ac4ac0a3575fafde31e659ced85f69c4d">wxlua_lreg_refs_key</a> = <span class="stringliteral">"wxLua Lua object refs"</span>;
- <a name="l00030"></a><a class="code" href="wxlstate_8cpp.html#a30c2d5556a4a278368b48fe0b7bb3fda">00030</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a30c2d5556a4a278368b48fe0b7bb3fda">wxlua_lreg_debug_refs_key</a> = <span class="stringliteral">"wxLuaDebugData refs"</span>;
- <a name="l00031"></a><a class="code" href="wxlstate_8cpp.html#a0bcf696ed6d6e2b4218e9a8852a164ef">00031</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a0bcf696ed6d6e2b4218e9a8852a164ef">wxlua_lreg_classes_key</a> = <span class="stringliteral">"wxLuaBindClass structs"</span>;
- <a name="l00032"></a><a class="code" href="wxlstate_8cpp.html#a274b8b7aae6f647e3e69d098962b7b1d">00032</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a274b8b7aae6f647e3e69d098962b7b1d">wxlua_lreg_derivedmethods_key</a> = <span class="stringliteral">"wxLua derived class methods"</span>;
- <a name="l00033"></a><a class="code" href="wxlstate_8cpp.html#a921299ed63513972e3bda3678fc835c0">00033</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a921299ed63513972e3bda3678fc835c0">wxlua_lreg_wxluastate_key</a> = <span class="stringliteral">"wxLuaState"</span>;
- <a name="l00034"></a><a class="code" href="wxlstate_8cpp.html#a80a0d4c84529abdcf6b46237431832ce">00034</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a80a0d4c84529abdcf6b46237431832ce">wxlua_lreg_wxluabindings_key</a> = <span class="stringliteral">"wxLuaBindings"</span>;
- <a name="l00035"></a><a class="code" href="wxlstate_8cpp.html#af255531a04d81a0d82556c0d1fe8e7e7">00035</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#af255531a04d81a0d82556c0d1fe8e7e7">wxlua_lreg_weakobjects_key</a> = <span class="stringliteral">"wxLua objects pushed"</span>;
- <a name="l00036"></a><a class="code" href="wxlstate_8cpp.html#a7ec5afec8a64a29e28fefec4a1105790">00036</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a7ec5afec8a64a29e28fefec4a1105790">wxlua_lreg_gcobjects_key</a> = <span class="stringliteral">"wxLua gc objects to delete"</span>;
- <a name="l00037"></a><a class="code" href="wxlstate_8cpp.html#a034985fb7df51670c3b6a024329496fa">00037</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a034985fb7df51670c3b6a024329496fa">wxlua_lreg_evtcallbacks_key</a> = <span class="stringliteral">"wxLuaEventCallbacks"</span>;
- <a name="l00038"></a><a class="code" href="wxlstate_8cpp.html#ae13b14073477671929c41823f198c33d">00038</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#ae13b14073477671929c41823f198c33d">wxlua_lreg_windestroycallbacks_key</a> = <span class="stringliteral">"wxLuaWinDestoyCallbacks"</span>;
- <a name="l00039"></a><a class="code" href="wxlstate_8cpp.html#aab2351a78a8949184e1910cc1f9e7463">00039</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#aab2351a78a8949184e1910cc1f9e7463">wxlua_lreg_topwindows_key</a> = <span class="stringliteral">"wxLua top level wxWindows"</span>;
- <a name="l00040"></a><a class="code" href="wxlstate_8cpp.html#a91d0a86787b3a1de5921590ce6a0b3e8">00040</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a91d0a86787b3a1de5921590ce6a0b3e8">wxlua_lreg_callbaseclassfunc_key</a> = <span class="stringliteral">"wxLua CallBaseClassFunc"</span>;
- <a name="l00041"></a><a class="code" href="wxlstate_8cpp.html#af24ccc441c899b3028cfc5d4099c739a">00041</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#af24ccc441c899b3028cfc5d4099c739a">wxlua_lreg_wxeventtype_key</a> = <span class="stringliteral">"wxLua wxEventType"</span>;
- <a name="l00042"></a><a class="code" href="wxlstate_8cpp.html#aba1ad42faf08e4b50bca48b5ba9d8ece">00042</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#aba1ad42faf08e4b50bca48b5ba9d8ece">wxlua_lreg_wxluastatedata_key</a> = <span class="stringliteral">"wxLuaStateData"</span>;
- <a name="l00043"></a><a class="code" href="wxlstate_8cpp.html#ab84cb2515893ab069d7d165208e68aad">00043</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#ab84cb2515893ab069d7d165208e68aad">wxlua_lreg_regtable_key</a> = <span class="stringliteral">"wxLua LUA_REGISTRYINDEX tables"</span>;
- <a name="l00044"></a>00044
- <a name="l00045"></a><a class="code" href="wxlstate_8cpp.html#a663c0f4ffbb1923edf3055b4c8c81ff9">00045</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a663c0f4ffbb1923edf3055b4c8c81ff9">wxlua_metatable_type_key</a> = <span class="stringliteral">"wxLua metatable class type"</span>;
- <a name="l00046"></a><a class="code" href="wxlstate_8cpp.html#a8719cfeea23ebd1cb309de8296777da6">00046</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="wxlstate_8h.html#a8719cfeea23ebd1cb309de8296777da6">wxlua_metatable_wxluabindclass_key</a> = <span class="stringliteral">"wxLua metatable wxLuaBindClass"</span>;
- <a name="l00047"></a>00047
- <a name="l00048"></a>00048 <a class="code" href="classwxLuaState.html">wxLuaState</a> <a class="code" href="wxlstate_8h.html#aef06b6591011cd68b9e370d5e702d255">wxNullLuaState</a>(<span class="keyword">false</span>);
- <a name="l00049"></a>00049
- <a name="l00050"></a>00050 <span class="keywordtype">int</span> LUACALL <a class="code" href="wxlstate_8cpp.html#ab03a3095ab5d0f4a427b4c5b10aa4e5c">luaopen_bit</a>(lua_State *L); <span class="comment">// implemented at bottom of file</span>
- <a name="l00051"></a>00051
- <a name="l00052"></a>00052 <span class="comment">// ----------------------------------------------------------------------------</span>
- <a name="l00053"></a>00053 <span class="comment">// C functions for Lua used in wxLuaState</span>
- <a name="l00054"></a>00054 <span class="comment">// ----------------------------------------------------------------------------</span>
- <a name="l00055"></a>00055
- <a name="l00056"></a>00056 <span class="comment">// The print function that we push into Lua replacing "print(...)"</span>
- <a name="l00057"></a>00057 <span class="comment">// to generate wxLuaEvent(wxEVT_LUA_PRINT, ...)</span>
- <a name="l00058"></a>00058 <span class="comment">// Code copied from Lua's luaB_print() function in lbaselib.c</span>
- <a name="l00059"></a><a class="code" href="wxlstate_8cpp.html#a7c982cbdf126f61b0868fe40baf150c4">00059</a> <span class="keywordtype">int</span> LUACALL <a class="code" href="wxlstate_8cpp.html#a7c982cbdf126f61b0868fe40baf150c4">wxlua_printFunction</a>( lua_State *L )
- <a name="l00060"></a>00060 {
- <a name="l00061"></a>00061 <a class="code" href="classwxLuaState.html">wxLuaState</a> wxlState(L); <span class="comment">// doesn't have to be ok</span>
- <a name="l00062"></a>00062
- <a name="l00063"></a>00063 wxString msg;
- <a name="l00064"></a>00064 <span class="keywordtype">int</span> i, n = lua_gettop(L);
- <a name="l00065"></a>00065
- <a name="l00066"></a>00066 <span class="comment">// Use the Lua tostring() function to print them as Lua would</span>
- <a name="l00067"></a>00067 lua_getglobal(L, <span class="stringliteral">"tostring"</span>);
- <a name="l00068"></a>00068
- <a name="l00069"></a>00069 <span class="keywordflow">if</span> (!lua_isfunction(L, -1))
- <a name="l00070"></a>00070 {
- <a name="l00071"></a>00071 <span class="comment">// This code is also used in wxledit.cpp, wxLuaShell::RunString()</span>
- <a name="l00072"></a>00072 msg = wxT(<span class="stringliteral">"wxLua ERROR: Unable to print() without the tostring() function. Did you remove it?"</span>);
- <a name="l00073"></a>00073 lua_pop(L, 1); <span class="comment">// pop the nil or whatever replaced tostring()</span>
- <a name="l00074"></a>00074 n = 0; <span class="comment">// don't let for loop run</span>
- <a name="l00075"></a>00075 }
- <a name="l00076"></a>00076
- <a name="l00077"></a>00077 <span class="keywordflow">for</span> (i = 1; i <= n; ++i)
- <a name="l00078"></a>00078 {
- <a name="l00079"></a>00079 <span class="keywordflow">if</span> (i > 1) msg.Append(wxT(<span class="stringliteral">"\t"</span>)); <span class="comment">// Lua uses a tab too in luaB_print</span>
- <a name="l00080"></a>00080
- <a name="l00081"></a>00081 <span class="keyword">const</span> <span class="keywordtype">char</span> *s;
- <a name="l00082"></a>00082 lua_pushvalue(L, -1); <span class="comment">/* function to be called */</span>
- <a name="l00083"></a>00083 lua_pushvalue(L, i); <span class="comment">/* value to print */</span>
- <a name="l00084"></a>00084 lua_call(L, 1, 1);
- <a name="l00085"></a>00085 s = lua_tostring(L, -1); <span class="comment">/* get result */</span>
- <a name="l00086"></a>00086 <span class="keywordflow">if</span> (s == NULL)
- <a name="l00087"></a>00087 {
- <a name="l00088"></a>00088 <span class="comment">// FIXME use wxlua_error here? right now wxlua_error doesn't do anything special - JL</span>
- <a name="l00089"></a>00089 <span class="keywordflow">return</span> luaL_error(L, LUA_QL(<span class="stringliteral">"tostring"</span>) <span class="stringliteral">" must return a string to "</span>
- <a name="l00090"></a>00090 LUA_QL(<span class="stringliteral">"print"</span>));
- <a name="l00091"></a>00091 }
- <a name="l00092"></a>00092 msg += <a class="code" href="wxlstate_8h.html#aaa3dbc7e667edd1e7409725fe338f4e8">lua2wx</a>(s);
- <a name="l00093"></a>00093 lua_pop(L, 1); <span class="comment">/* pop result */</span>
- <a name="l00094"></a>00094 }
- <a name="l00095"></a>00095
- <a name="l00096"></a>00096 <span class="keywordflow">if</span> (!msg.IsEmpty() && wxlState.<a class="code" href="classwxLuaState.html#a0a2d167b9d6d1259066d9aa771ad075e">Ok</a>())
- <a name="l00097"></a>00097 {
- <a name="l00098"></a>00098 <a class="code" href="classwxLuaEvent.html">wxLuaEvent</a> event(wxEVT_LUA_PRINT, wxlState.<a class="code" href="classwxLuaState.html#a92715872ca9f5f4b6e77344410963350">GetId</a>(), wxlState);
- <a name="l00099"></a>00099 <span class="keyword">event</span>.SetString(msg);
- <a name="l00100"></a>00100 wxlState.<a class="code" href="classwxLuaState.html#a1f0e0a065e8c3ea25c0ebe5c7258f7ae">SendEvent</a>(event);
- <a name="l00101"></a>00101 }
- <a name="l00102"></a>00102 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!msg.IsEmpty())
- <a name="l00103"></a>00103 wxPrintf(wxT(<span class="stringliteral">"%s\n"</span>), msg.c_str()); <span class="comment">// Lua puts a \n too</span>
- <a name="l00104"></a>00104
- <a name="l00105"></a>00105 <span class="keywordflow">return</span> 0; <span class="comment">// no items put onto stack</span>
- <a name="l00106"></a>00106 }
- <a name="l00107"></a>00107
- <a name="l00108"></a><a class="code" href="wxlstate_8cpp.html#a9eab35a72e3a0d8e1a669fb831a5272d">00108</a> <span class="keywordtype">void</span> LUACALL <a class="code" href="wxlstate_8cpp.html#a9eab35a72e3a0d8e1a669fb831a5272d">wxlua_debugHookFunction</a>(lua_State *L, lua_Debug *LDebug)
- <a name="l00109"></a>00109 {
- <a name="l00110"></a>00110 <span class="comment">// NULL when shutting down.</span>
- <a name="l00111"></a>00111 <a class="code" href="classwxLuaStateData.html">wxLuaStateData</a>* wxlStateData = <a class="code" href="wxlstate_8h.html#a4c7701b4b056e2f84f380be559bb2482">wxlua_getwxluastatedata</a>(L);
- <a name="l00112"></a>00112 <span class="keywordflow">if</span> (!wxlStateData) <span class="keywordflow">return</span>;
- <a name="l00113"></a>00113
- <a name="l00114"></a>00114 <span class="comment">// FIXME - for select event types we don't want to do anything</span>
- <a name="l00115"></a>00115 wxEventType evtType = <a class="code" href="wxlstate_8h.html#a5442b3e5a2f8dca8fb920c00279385ac">wxlua_getwxeventtype</a>(L);
- <a name="l00116"></a>00116 <span class="keywordflow">if</span> ((evtType != wxEVT_NULL))
- <a name="l00117"></a>00117 <span class="comment">//(evtType == wxEVT_IDLE) && (evtType == wxEVT_PAINT) &&</span>
- <a name="l00118"></a>00118 <span class="comment">//(evtType == wxEVT_DESTROY) && (evtType == wxEVT_CLOSE_WINDOW))</span>
- <a name="l00119"></a>00119 <span class="keywordflow">return</span>;
- <a name="l00120"></a>00120
- <a name="l00121"></a>00121 <span class="comment">// they want to break the program, restore old debug hook, then error out</span>
- <a name="l00122"></a>00122 <span class="keywordflow">if</span> (wxlStateData-><a class="code" href="classwxLuaStateData.html#abb85e04d6c6dd5a5b31ec55c3c3fdd8f">m_debug_hook_break</a>)
- <a name="l00123"></a>00123 {
- <a name="l00124"></a>00124 <span class="comment">// It's ok that we get the wxLuaState here since we're stopping anyway.</span>
- <a name="l00125"></a>00125 <a class="code" href="classwxLuaState.html">wxLuaState</a> wxlState(L);
- <a name="l00126"></a>00126
- <a name="l00127"></a>00127 <span class="comment">// restore hook to previous state</span>
- <a name="l00128"></a>00128 wxlState.<a class="code" href="classwxLuaState.html#a61b2c790f1b50df9c8b41ef6cc8e58e9">ClearDebugHookBreak</a>();
- <a name="l00129"></a>00129 <a class="code" href="wxlstate_8h.html#a1abe07e896f1e813fc28da0e0d92961a">wxlua_error</a>(L, wxlStateData-><a class="code" href="classwxLuaStateData.html#a375859ee7c4407fb3c5588b39705de2d">m_debug_hook_break_msg</a>);
- <a name="l00130"></a>00130 <span class="keywordflow">return</span>;
- <a name="l00131"></a>00131 }
- <a name="l00132"></a>00132
- <a name="l00133"></a>00133 <span class="comment">// Assume they've set the wxEvtHandler, ok if not, but it wouldn't make sense</span>
- <a name="l00134"></a>00134 <span class="comment">// We use wxLuaState::SendEvent() because it sets wxEvent::SetEventObject() for us.</span>
- <a name="l00135"></a>00135 <span class="keywordflow">if</span> (wxlStateData-><a class="code" href="classwxLuaStateData.html#adee2d0bdd61585268fc43c18bd0d1116">m_lua_debug_hook_send_evt</a>)
- <a name="l00136"></a>00136 {
- <a name="l00137"></a>00137 <a class="code" href="classwxLuaState.html">wxLuaState</a> wxlState(L);
- <a name="l00138"></a>00138
- <a name="l00139"></a>00139 <span class="keywordtype">int</span> ret = 0;
- <a name="l00140"></a>00140 ret = lua_getinfo(L, <span class="stringliteral">"l"</span>, LDebug); <span class="comment">// line (ldebug.currentline)</span>
- <a name="l00141"></a>00141
- <a name="l00142"></a>00142 <a class="code" href="classwxLuaEvent.html">wxLuaEvent</a> event(wxEVT_LUA_DEBUG_HOOK, wxlState.<a class="code" href="classwxLuaState.html#a92715872ca9f5f4b6e77344410963350">GetId</a>(), wxlState);
- <a name="l00143"></a>00143 <span class="keyword">event</span>.m_lua_Debug = LDebug;
- <a name="l00144"></a>00144 <span class="keyword">event</span>.SetInt(LDebug->currentline);
- <a name="l00145"></a>00145 wxlState.<a class="code" href="classwxLuaState.html#a1f0e0a065e8c3ea25c0ebe5c7258f7ae">SendEvent</a>( event );
- <a name="l00146"></a>00146 <span class="keywordflow">if</span> (event.m_debug_hook_break)
- <a name="l00147"></a>00147 wxlState.<a class="code" href="classwxLuaState.html#a4925fb35a1622f81fc9c5dc5820e27d8">wxlua_Error</a>(<span class="stringliteral">"Lua interpreter stopped."</span>);
- <a name="l00148"></a>00148 }
- <a name="l00149"></a>00149
- <a name="l00150"></a>00150 <span class="comment">// Try to yield *after* sending event to allow C++ gui update</span>
- <a name="l00151"></a>00151 <span class="keywordflow">if</span> (wxlStateData-><a class="code" href="classwxLuaStateData.html#a16aa632cff2de6c2ee2e2cab9a03b9a1">m_lua_debug_hook_yield</a> > 0)
- <a name="l00152"></a>00152 {
- <a name="l00153"></a>00153 <span class="comment">// yield based on number of ms passed NOT every hook event</span>
- <a name="l00154"></a>00154 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> last_time = wxlStateData-><a class="code" href="classwxLuaStateData.html#aa7500e45a81ca35fc3fe1b66c2aa38fd">m_last_debug_hook_time</a>;
- <a name="l00155"></a>00155 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> cur_time = wxGetLocalTimeMillis().GetLo();
- <a name="l00156"></a>00156
- <a name="l00157"></a>00157 <span class="keywordflow">if</span> ((cur_time > last_time + wxlStateData-><a class="code" href="classwxLuaStateData.html#a16aa632cff2de6c2ee2e2cab9a03b9a1">m_lua_debug_hook_yield</a>) ||
- <a name="l00158"></a>00158 (cur_time < last_time)) <span class="comment">// wrapped</span>
- <a name="l00159"></a>00159 {
- <a name="l00160"></a>00160 wxlStateData-><a class="code" href="classwxLuaStateData.html#aa7500e45a81ca35fc3fe1b66c2aa38fd">m_last_debug_hook_time</a> = cur_time;
- <a name="l00161"></a>00161
- <a name="l00162"></a>00162 <span class="keywordtype">bool</span> painting = (evtType == wxEVT_PAINT);
- <a name="l00163"></a>00163
- <a name="l00164"></a>00164 <span class="comment">/*</span>
- <a name="l00165"></a>00165 <span class="comment"> wxLongToLongHashMap::iterator it;</span>
- <a name="l00166"></a>00166 <span class="comment"> wxLongToLongHashMap* hashMap = &wxlState.GetLuaStateRefData()->m_wxlStateData->m_trackedObjects;</span>
- <a name="l00167"></a>00167 <span class="comment"> for (it = hashMap->begin(); it != hashMap->end(); ++it)</span>
- <a name="l00168"></a>00168 <span class="comment"> {</span>
- <a name="l00169"></a>00169 <span class="comment"> wxObject* obj = (wxObject*)it->second;</span>
- <a name="l00170"></a>00170 <span class="comment"> if (obj && wxDynamicCast(obj, wxPaintDC))</span>
- <a name="l00171"></a>00171 <span class="comment"> {</span>
- <a name="l00172"></a>00172 <span class="comment"> painting = true;</span>
- <a name="l00173"></a>00173 <span class="comment"> break;</span>
- <a name="l00174"></a>00174 <span class="comment"> }</span>
- <a name="l00175"></a>00175 <span class="comment"> }</span>
- <a name="l00176"></a>00176 <span class="comment">*/</span>
- <a name="l00177"></a>00177
- <a name="l00178"></a>00178 <span class="keywordflow">if</span> (!painting)
- <a name="l00179"></a>00179 wxYield(); <span class="comment">//IfNeeded();</span>
- <a name="l00180"></a>00180 }
- <a name="l00181"></a>00181 }
- <a name="l00182"></a>00182 }
- <a name="l00183"></a>00183
- <a name="l00184"></a>00184 <span class="comment">// ----------------------------------------------------------------------------</span>
- <a name="l00185"></a>00185
- <a name="l00186"></a><a class="code" href="wxlstate_8cpp.html#a7185a0c6fb640503f4921f15811ff4ac">00186</a> <span class="keywordtype">void</span> <a class="code" href="wxlstate_8h.html#a78fe2540c7e61145be1372073f0c37f7">wxlua_lreg_createtable</a>(lua_State* L, <span class="keywordtype">void</span>* lightuserdata_reg_key, <span class="keywordtype">int</span> narr, <span class="keywordtype">int</span> nrec)
- <a name="l00187"></a>00187 {
- <a name="l00188"></a>00188 <span class="comment">// clear the old ref to the table, even though it's weak kv</span>
- <a name="l00189"></a>00189 <span class="comment">// it doesn't get cleared until the gc runs</span>
- <a name="l00190"></a>00190 lua_pushlightuserdata(L, &<a class="code" href="wxlstate_8h.html#ab84cb2515893ab069d7d165208e68aad">wxlua_lreg_regtable_key</a>); <span class="comment">// push key</span>
- <a name="l00191"></a>00191 lua_rawget(L, LUA_REGISTRYINDEX); <span class="comment">// get table</span>
- <a name="l00192"></a>00192 lua_pushlightuserdata(L, lightuserdata_reg_key); <span class="comment">// push key</span>
- <a name="l00193"></a>00193 lua_rawget(L, LUA_REGISTRYINDEX); <span class="comment">// get table or nil</span>
- <a name="l00194"></a>00194 <span class="keywordflow">if</span> (lua_istable(L, -1))
- <a name="l00195"></a>00195 {
- <a name="l00196"></a>00196 lua_pushnil(L); <span class="comment">// push value</span>
- <a name="l00197"></a>00197 lua_rawset(L, -3); <span class="comment">// clear t[key] = nil</span>
- <a name="l00198"></a>00198 lua_pop(L, 1); <span class="comment">// pop wxlua_lreg_regtable_key table</span>
- <a name="l00199"></a>00199 }
- <a name="l00200"></a>00200 <span class="keywordflow">else</span>
- <a name="l00201"></a>00201 lua_pop(L, 2); <span class="comment">// pop nil and wxlua_lreg_regtable_key table</span>
- <a name="l00202"></a>00202
- <a name="l00203"></a>00203 <span class="comment">// Add new LUA_REGISTRYINDEX[&wxlua_lreg_regtable_key][lightuserdata_reg_key table] = lightuserdata_reg_key</span>
- <a name="l00204"></a>00204 lua_pushlightuserdata(L, lightuserdata_reg_key); <span class="comment">// push key</span>
- <a name="l00205"></a>00205 lua_createtable(L, narr, nrec); <span class="comment">// push value</span>
- <a name="l00206"></a>00206 lua_pushlightuserdata(L, &<a class="code" href="wxlstate_8h.html#ab84cb2515893ab069d7d165208e68aad">wxlua_lreg_regtable_key</a>); <span class="comment">// push key</span>
- <a name="l00207"></a>00207 lua_rawget(L, LUA_REGISTRYINDEX); <span class="comment">// get wxlua_lreg_regtable_key table</span>
- <a name="l00208"></a>00208 lua_pushvalue(L, -2); <span class="comment">// push key (copy of the new table)</span>
- <a name="l00209"></a>00209 lua_pushvalue(L, -4); <span class="comment">// push value (copy of lightuserdata key)</span>
- <a name="l00210"></a>00210 lua_rawset(L, -3); <span class="comment">// set t[key] = value; pops key and value</span>
- <a name="l00211"></a>00211 lua_pop(L, 1); <span class="comment">// pop wxlua_lreg_regtable_key table</span>
- <a name="l00212"></a>00212 lua_rawset(L, LUA_REGISTRYINDEX); <span class="comment">// set the value</span>
- <a name="l00213"></a>00213 }
- <a name="l00214"></a>00214
- <a name="l00215"></a>00215 <span class="comment">// ----------------------------------------------------------------------------</span>
- <a name="l00216"></a>00216 <span class="comment">// Lua helper functions</span>
- <a name="l00217"></a>00217 <span class="comment">// ----------------------------------------------------------------------------</span>
- <a name="l00218"></a>00218
- <a name="l00219"></a><a class="code" href="wxlstate_8cpp.html#ab2ae5dfea9cc867ed46ed094ce4e768f">00219</a> wxString <a class="code" href="wxlstate_8h.html#ab2ae5dfea9cc867ed46ed094ce4e768f">wxlua_LUA_ERR_msg</a>(<span class="keywordtype">int</span> LUA_ERRx)
- <a name="l00220"></a>00220 {
- <a name="l00221"></a>00221 <span class="keywordflow">switch</span> (LUA_ERRx)
- <a name="l00222"></a>00222 {
- <a name="l00223"></a>00223 <span class="keywordflow">case</span> 0 : <span class="keywordflow">return</span> wxEmptyString;
- <a name="l00224"></a>00224 <span class="keywordflow">case</span> LUA_YIELD : <span class="keywordflow">return</span> wxT(<span class="stringliteral">"Lua: Thread is suspended"</span>);
- <a name="l00225"></a>00225 <span class="keywordflow">case</span> LUA_ERRRUN : <span class="keywordflow">return</span> wxT(<span class="stringliteral">"Lua: Error while running chunk"</span>);
- <a name="l00226"></a>00226 <span class="keywordflow">case</span> LUA_ERRSYNTAX : <span class="keywordflow">return</span> wxT(<span class="stringliteral">"Lua: Syntax error during pre-compilation"</span>);
- <a name="l00227"></a>00227 <span class="keywordflow">case</span> LUA_ERRMEM : <span class="keywordflow">return</span> wxT(<span class="stringliteral">"Lua: Memory allocation error"</span>);
- <a name="l00228"></a>00228 <span class="keywordflow">case</span> LUA_ERRERR : <span class="keywordflow">return</span> wxT(<span class="stringliteral">"Lua: Generic error or an error occurred while running the error handler"</span>);
- <a name="l00229"></a>00229 <span class="keywordflow">case</span> LUA_ERRFILE : <span class="keywordflow">return</span> wxT(<span class="stringliteral">"Lua: Error occurred while opening file"</span>);
- <a name="l00230"></a>00230 }
- <a name="l00231"></a>00231
- <a name="l00232"></a>00232 <span class="keywordflow">return</span> wxT(<span class="stringliteral">"Lua: Unknown LUA_ERRx error value"</span>);
- <a name="l00233"></a>00233 }
- <a name="l00234"></a>00234
- <a name="l00235"></a><a class="code" href="wxlstate_8cpp.html#a0c9eeb57ad65f8e174030f03af466331">00235</a> <span class="keywordtype">bool</span> <a class="code" href="wxlstate_8h.html#a34d4dc64c6615a3e7c4fea5f6fb5840f">wxlua_errorinfo</a>(lua_State* L, <span class="keywordtype">int</span> status, <span class="keywordtype">int</span> top, wxString* errorMsg_, <span class="keywordtype">int</span>* line_num_)
- <a name="l00236"></a>00236 {
- <a name="l00237"></a>00237 <span class="keywordflow">if</span> (status == 0)
- <a name="l00238"></a>00238 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00239"></a>00239
- <a name="l00240"></a>00240 <span class="keywordtype">int</span> newtop = lua_gettop(L);
- <a name="l00241"></a>00241
- <a name="l00242"></a>00242 wxString errorMsg = <a class="code" href="wxlstate_8h.html#ab2ae5dfea9cc867ed46ed094ce4e768f">wxlua_LUA_ERR_msg</a>(status);
- <a name="l00243"></a>00243
- <a name="l00244"></a>00244 <span class="keywordflow">switch</span>(status)
- <a name="l00245"></a>00245 {
- <a name="l00246"></a>00246 <span class="keywordflow">case</span> LUA_ERRMEM:
- <a name="l00247"></a>00247 <span class="keywordflow">case</span> LUA_ERRERR:
- <a name="l00248"></a>00248 {
- <a name="l00249"></a>00249 <span class="keywordflow">if</span> (newtop > top)
- <a name="l00250"></a>00250 errorMsg += wxT(<span class="stringliteral">"\n"</span>);
- <a name="l00251"></a>00251 <span class="keywordflow">break</span>;
- <a name="l00252"></a>00252 }
- <a name="l00253"></a>00253 <span class="keywordflow">case</span> LUA_ERRRUN:
- <a name="l00254"></a>00254 <span class="keywordflow">case</span> LUA_ERRFILE:
- <a name="l00255"></a>00255 <span class="keywordflow">case</span> LUA_ERRSYNTAX:
- <a name="l00256"></a>00256 <span class="keywordflow">default</span>:
- <a name="l00257"></a>00257 {
- <a name="l00258"></a>00258 <span class="keywordflow">if</span> (newtop > top)
- <a name="l00259"></a>00259 errorMsg += wxT(<span class="stringliteral">"\n"</span>) + <a class="code" href="wxlstate_8h.html#aaa3dbc7e667edd1e7409725fe338f4e8">lua2wx</a>(lua_tostring(L, -1));
- <a name="l00260"></a>00260 <span class="keywordflow">break</span>;
- <a name="l00261"></a>00261 }
- <a name="l00262"></a>00262 }
- <a name="l00263"></a>00263
- <a name="l00264"></a>00264 errorMsg += wxT(<span class="stringliteral">"\n"</span>);
- <a name="l00265"></a>00265
- <a name="l00266"></a>00266 <span class="comment">// Why can't I fill a lua_Debug here? Try to get the line number</span>
- <a name="l00267"></a>00267 <span class="comment">// by parsing the error message that looks like this, 3 is linenumber</span>
- <a name="l00268"></a>00268 <span class="comment">// [string "a = 1("]:3: unexpected symbol near `<eof>'</span>
- <a name="l00269"></a>00269 wxString lineStr = errorMsg;
- <a name="l00270"></a>00270 <span class="keywordtype">long</span> line_num = -1;
- <a name="l00271"></a>00271 <span class="keywordflow">while</span>(!lineStr.IsEmpty())
- <a name="l00272"></a>00272 {
- <a name="l00273"></a>00273 <span class="comment">// search through the str to find ']:LONG:' pattern</span>
- <a name="l00274"></a>00274 lineStr = lineStr.AfterFirst(wxT(<span class="charliteral">']'</span>));
- <a name="l00275"></a>00275 <span class="keywordflow">if</span> ((lineStr.Length() > 0) && (lineStr.GetChar(0) == wxT(<span class="charliteral">':'</span>)))
- <a name="l00276"></a>00276 {
- <a name="l00277"></a>00277 lineStr = lineStr.AfterFirst(wxT(<span class="charliteral">':'</span>));
- <a name="l00278"></a>00278 <span class="keywordflow">if</span> (lineStr.IsEmpty() || lineStr.BeforeFirst(wxT(<span class="charliteral">':'</span>)).ToLong(&line_num))
- <a name="l00279"></a>00279 <span class="keywordflow">break</span>;
- <a name="l00280"></a>00280 }
- <a name="l00281"></a>00281 }
- <a name="l00282"></a>00282
- <a name="l00283"></a>00283 lua_settop(L, top); <span class="comment">// pops the message if any</span>
- <a name="l00284"></a>00284
- <a name="l00285"></a>00285 <span class="keywordflow">if</span> (errorMsg_) *errorMsg_ = errorMsg;
- <a name="l00286"></a>00286 <span class="keywordflow">if</span> (line_num_) *line_num_ = (int)line_num;
- <a name="l00287"></a>00287
- <a name="l00288"></a>00288 <span class="keywordflow">return</span> <span class="keyword">true</span>;
- <a name="l00289"></a>00289 }
- <a name="l00290"></a>00290
- <a name="l00291"></a><a class="code" href="wxlstate_8cpp.html#a1abe07e896f1e813fc28da0e0d92961a">00291</a> <span class="keywordtype">void</span> LUACALL <a class="code" href="wxlstate_8h.html#a1abe07e896f1e813fc28da0e0d92961a">wxlua_error</a>(lua_State *L, <span class="keyword">const</span> <span class="keywordtype">char</span> *errorMsg)
- <a name="l00292"></a>00292 {
- <a name="l00293"></a>00293 <span class="comment">// Use luaL_error(L, s) and not "lua_pushstring(L, s); lua_error(L)" since</span>
- <a name="l00294"></a>00294 <span class="comment">// luaL_error() provides the file and line number too.</span>
- <a name="l00295"></a>00295 luaL_error(L, <span class="stringliteral">"%s"</span>, errorMsg);
- <a name="l00296"></a>00296 }
- <a name="l00297"></a>00297
- <a name="l00298"></a><a class="code" href="wxlstate_8cpp.html#aba05dfc5f8a48e264d7463a7c6fee965">00298</a> <span class="keywordtype">void</span> LUACALL <a class="code" href="wxlstate_8h.html#aba05dfc5f8a48e264d7463a7c6fee965">wxlua_argerror</a>(lua_State *L, <span class="keywordtype">int</span> stack_idx, <span class="keyword">const</span> wxString& expectedType)
- <a name="l00299"></a>00299 {
- <a name="l00300"></a>00300 wxString argType = <a class="code" href="wxlstate_8h.html#acf6d708626f3c7194d1f2aebb7a73b6e">wxlua_luaL_typename</a>(L, stack_idx);
- <a name="l00301"></a>00301
- <a name="l00302"></a>00302 wxString msg(wxString::Format(_(<span class="stringliteral">"wxLua: Expected %s for parameter %d, but got a '%s'."</span>),
- <a name="l00303"></a>00303 expectedType.c_str(), stack_idx, argType.c_str()));
- <a name="l00304"></a>00304
- <a name="l00305"></a>00305 <a class="code" href="wxlstate_8h.html#a34376827e7b3466173127fba976217d0">wxlua_argerrormsg</a>(L, msg);
- <a name="l00306"></a>00306 }
- <a name="l00307"></a>00307
- <a name="l00308"></a><a class="code" href="wxlstate_8cpp.html#aa4db1ed30ef56e312dcf5e9cca75bcb2">00308</a> <span class="keywordtype">void</span> LUACALL <a class="code" href="wxlstate_8h.html#a34376827e7b3466173127fba976217d0">wxlua_argerrormsg</a>(lua_State *L, <span class="keyword">const</span> wxString& msg_)
- <a name="l00309"></a>00309 {
- <a name="l00310"></a>00310 wxString funcArgs(wxT(<span class="stringliteral">"\n"</span>));
- <a name="l00311"></a>00311 wxString argMsg = <a class="code" href="wxlbind_8h.html#a15f78fa970b76c7963c3e11f90d988ca">wxlua_getLuaArgsMsg</a>(L, 1, lua_gettop(L));
- <a name="l00312"></a>00312
- <a name="l00313"></a>00313 <a class="code" href="structwxLuaBindMethod.html">wxLuaBindMethod</a>* wxlMethod = (<a class="code" href="structwxLuaBindMethod.html">wxLuaBindMethod</a> *)lua_touserdata(L, lua_upvalueindex(1)); <span class="comment">// lightuserdata</span>
- <a name="l00314"></a>00314 <span class="keywordflow">if</span> (wxlMethod != NULL)
- <a name="l00315"></a>00315 {
- <a name="l00316"></a>00316 <span class="comment">// Guarantee that this is a wxLuaBindMethod of ours so we don't crash.</span>
- <a name="l00317"></a>00317 <span class="comment">// Since we're going to error out we don't have to be quick about it.</span>
- <a name="l00318"></a>00318
- <a name="l00319"></a>00319 <span class="comment">// check if this method is part of a class</span>
- <a name="l00320"></a>00320 <span class="keyword">const</span> <a class="code" href="structwxLuaBindClass.html">wxLuaBindClass</a>* wxlClass = <a class="code" href="classwxLuaBinding.html#a7ee5e4f66198a0ef9e8cc4c2a6d0318e">wxLuaBinding::FindBindClass</a>(wxlMethod);
- <a name="l00321"></a>00321
- <a name="l00322"></a>00322 <span class="comment">// if not, check if it's a global C style function</span>
- <a name="l00323"></a>00323 <a class="code" href="classwxLuaBinding.html">wxLuaBinding</a>* binding = NULL;
- <a name="l00324"></a>00324 <span class="keywordflow">if</span> (wxlClass == NULL)
- <a name="l00325"></a>00325 binding = <a class="code" href="classwxLuaBinding.html#a463d056fe9bcb54f0408a8ae523ba64e">wxLuaBinding::FindMethodBinding</a>(wxlMethod);
- <a name="l00326"></a>00326
- <a name="l00327"></a>00327 <span class="keywordflow">if</span> ((wxlClass != NULL) || (binding != NULL))
- <a name="l00328"></a>00328 funcArgs += <a class="code" href="wxlbind_8h.html#a0cf1f6600d0f80e2135c6788a4afc39f">wxlua_getBindMethodArgsMsg</a>(L, wxlMethod);
- <a name="l00329"></a>00329 }
- <a name="l00330"></a>00330
- <a name="l00331"></a>00331 wxString msg = msg_ + wxT(<span class="stringliteral">"\nFunction called: '"</span>) + argMsg + wxT(<span class="stringliteral">"'"</span>) + funcArgs;
- <a name="l00332"></a>00332 <a class="code" href="wxlstate_8h.html#a1abe07e896f1e813fc28da0e0d92961a">wxlua_error</a>(L, msg);
- <a name="l00333"></a>00333 }
- <a name="l00334"></a>00334
- <a name="l00335"></a><a class="code" href="wxlstate_8cpp.html#adde66f46b163a0fc59e09904cf355792">00335</a> <span class="keywordtype">void</span>* LUACALL <a class="code" href="wxlstate_8h.html#ac5a0a65665274df59adbed667480e93e">wxlua_touserdata</a>(lua_State *L, <span class="keywordtype">int</span> stack_idx, <span class="keywordtype">bool</span> null_ptr <span class="comment">/*= false*/</span>)
- <a name="l00336"></a>00336 {
- <a name="l00337"></a>00337 <span class="keywordtype">void</span> *pdata = NULL;
- <a name="l00338"></a>00338 <span class="keywordtype">void</span> **ptr = (<span class="keywordtype">void</span> **)lua_touserdata(L, stack_idx);
- <a name="l00339"></a>00339
- <a name="l00340"></a>00340 <span class="keywordflow">if</span> (ptr != NULL)
- <a name="l00341"></a>00341 {
- <a name="l00342"></a>00342 pdata = *ptr; <span class="comment">// get the pointer the userdata holds</span>
- <a name="l00343"></a>00343 <span class="keywordflow">if</span> (null_ptr) <span class="comment">// NULL ptr so Lua won't try to gc it</span>
- <a name="l00344"></a>00344 *ptr = NULL;
- <a name="l00345"></a>00345 }
- <a name="l00346"></a>00346
- <a name="l00347"></a>00347 <span class="keywordflow">return</span> pdata;
- <a name="l00348"></a>00348 }
- <a name="l00349"></a>00349
- <a name="l00350"></a>00350 <span class="comment">// ----------------------------------------------------------------------------</span>
- <a name="l00351"></a>00351 <span class="comment">// wxluaR_XXX - functions operate on tables in Lua's LUA_REGISTRYINDEX</span>
- <a name="l00352"></a>00352 <span class="comment">// ----------------------------------------------------------------------------</span>
- <a name="l00353"></a>00353
- <a name="l00354"></a><a class="code" href="wxlstate_8cpp.html#a08525c218f0a90e660c0f816906da29e">00354</a> <span class="preprocessor">#define ABS_LUA_STKIDX(n, added_items) ((n) > 0 ? (n) : (n)-(added_items))</span>
- <a name="l00355"></a>00355 <span class="preprocessor"></span>
- <a name="l00356"></a>00356 <span class="comment">// Note about luaL_ref() and luaL_unref().</span>
- <a name="l00357"></a>00357 <span class="comment">// ref creates integer numbers from 1 to ...</span>
- <a name="l00358"></a>00358 <span class="comment">// unref uses t[0] to hold the last unused reference and when you call unref</span>
- <a name="l00359"></a>00359 <span class="comment">// again the next unused ref points back to the first and t[0] points to the</span>
- <a name="l00360"></a>00360 <span class="comment">// last unrefed key.</span>
- <a name="l00361"></a>00361 <span class="comment">// eg. create 5 refs, get refs 1,2,3,4,5, then call unref on 3 then 4 then</span>
- <a name="l00362"></a>00362 <span class="comment">// call ref 3 times and the new references will be 4, 3, 6</span>
- <a name="l00363"></a>00363
- <a name="l00364"></a><a class="code" href="wxlstate_8cpp.html#a0879809a008c75f8b26fb9ee326efdbd">00364</a> <span class="keywordtype">int</span> <a class="code" href="wxlstate_8h.html#acbf0a32ad4b828026bd7f643557646d0">wxluaR_ref</a>(lua_State* L, <span class="keywordtype">int</span> stack_idx, <span class="keywordtype">void</span>* lightuserdata_reg_key)
- <a name="l00365"></a>00365 {
- <a name="l00366"></a>00366 <span class="comment">// nothing on stack to insert and don't bother inserting nil</span>
- <a name="l00367"></a>00367 <span class="keywordflow">if</span> (lua_isnoneornil(L, stack_idx))
- <a name="l00368"></a>00368 <span class="keywordflow">return</span> LUA_REFNIL;
- <a name="l00369"></a>00369
- <a name="l00370"></a>00370 lua_pushlightuserdata(L, lightuserdata_reg_key); <span class="comment">// push key</span>
- <a name="l00371"></a>00371 lua_rawget(L, LUA_REGISTRYINDEX); <span class="comment">// pop key, push value (table)</span>
- <a name="l00372"></a>00372
- <a name="l00373"></a>00373 lua_pushvalue(L, <a class="code" href="wxlstate_8cpp.html#a08525c218f0a90e660c0f816906da29e">ABS_LUA_STKIDX</a>(stack_idx,1)); <span class="comment">// push value to store</span>
- <a name="l00374"></a>00374
- <a name="l00375"></a>00375 <span class="keywordtype">int</span> ref_idx = luaL_ref(L, -2); <span class="comment">// t[ref_idx] = value; pops value</span>
- <a name="l00376"></a>00376
- <a name="l00377"></a>00377 <span class="comment">// We also store t[value] = table_idx for this table for faster lookup</span>
- <a name="l00378"></a>00378 <span class="keywordflow">if</span> (lightuserdata_reg_key == &<a class="code" href="wxlstate_8h.html#a30c2d5556a4a278368b48fe0b7bb3fda">wxlua_lreg_debug_refs_key</a>)
- <a name="l00379"></a>00379 {
- <a name="l00380"></a>00380 lua_pushvalue(L, <a class="code" href="wxlstate_8cpp.html#a08525c218f0a90e660c0f816906da29e">ABS_LUA_STKIDX</a>(stack_idx,1)); <span class="comment">// push key</span>
- <a name="l00381"></a>00381 lua_pushnumber(L, ref_idx); <span class="comment">// push value</span>
- <a name="l00382"></a>00382 lua_rawset(L, -3); <span class="comment">// set t[key] = value; pops key and value</span>
- <a name="l00383"></a>00383 }
- <a name="l00384"></a>00384
- <a name="l00385"></a>00385 lua_pop(L, 1); <span class="comment">// pop table</span>
- <a name="l00386"></a>00386
- <a name="l00387"></a>00387 <span class="keywordflow">return</span> ref_idx;
- <a name="l00388"></a>00388 }
- <a name="l00389"></a>00389
- <a name="l00390"></a><a class="code" href="wxlstate_8cpp.html#a78110a111c2f4e0a94231d344611ce20">00390</a> <span class="keywordtype">bool</span> <a class="code" href="wxlstate_8h.html#a0578d177f35b4dd05177067425410009">wxluaR_unref</a>(lua_State* L, <span class="keywordtype">int</span> ref_idx, <span class="keywordtype">void</span>* lightuserdata_reg_key)
- <a name="l00391"></a>00391 {
- <a name="l00392"></a>00392 <span class="keywordflow">if</span> (ref_idx == LUA_REFNIL) <span class="comment">// nothing to remove</span>
- <a name="l00393"></a>00393 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00394"></a>00394
- <a name="l00395"></a>00395 lua_pushlightuserdata(L, lightuserdata_reg_key); <span class="comment">// push key</span>
- <a name="l00396"></a>00396 lua_rawget(L, LUA_REGISTRYINDEX); <span class="comment">// pop key, push value (table)</span>
- <a name="l00397"></a>00397
- <a name="l00398"></a>00398 <span class="comment">// Also remove the t[value] = table_idx for this table</span>
- <a name="l00399"></a>00399 <span class="keywordflow">if</span> (lightuserdata_reg_key == &<a class="code" href="wxlstate_8h.html#a30c2d5556a4a278368b48fe0b7bb3fda">wxlua_lreg_debug_refs_key</a>)
- <a name="l00400"></a>00400 {
- <a name="l00401"></a>00401 lua_pushnumber(L, ref_idx); <span class="comment">// push key</span>
- <a name="l00402"></a>00402 lua_rawget(L, -2); <span class="comment">// get t[key] = value; pop key, push value;</span>
- <a name="l00403"></a>00403
- <a name="l00404"></a>00404 lua_pushnil(L);
- <a name="l00405"></a>00405 lua_rawset(L, -3); <span class="comment">// t[value] = nil; pops key and value</span>
- <a name="l00406"></a>00406 }
- <a name="l00407"></a>00407
- <a name="l00408"></a>00408 luaL_unref(L, -1, ref_idx); <span class="comment">// remove key and value in refs table</span>
- <a name="l00409"></a>00409 <span class="comment">// note: this key will be used for the next wxluaR_ref()</span>
- <a name="l00410"></a>00410
- <a name="l00411"></a>00411 lua_pop(L, 1); <span class="comment">// pop table</span>
- <a name="l00412"></a>00412
- <a name="l00413"></a>00413 <span class="keywordflow">return</span> <span class="keyword">true</span>;
- <a name="l00414"></a>00414 }
- <a name="l00415"></a>00415
- <a name="l00416"></a><a class="code" href="wxlstate_8cpp.html#a72d9705f9b5d46e0183888f4846d8e82">00416</a> <span class="keywordtype">bool</span> LUACALL <a class="code" href="wxlstate_8h.html#ae7108b396d79179f517a7dc478c2cb43">wxluaR_getref</a>(lua_State *L, <span class="keywordtype">int</span> ref_idx, <span class="keywordtype">void</span>* lightuserdata_reg_key)
- <a name="l00417"></a>00417 {
- <a name="l00418"></a>00418 <span class="keywordflow">if</span> (ref_idx == LUA_REFNIL) <span class="comment">// nothing to get</span>
- <a name="l00419"></a>00419 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00420"></a>00420
- <a name="l00421"></a>00421 lua_pushlightuserdata(L, lightuserdata_reg_key); <span class="comment">// push key</span>
- <a name="l00422"></a>00422 lua_rawget(L, LUA_REGISTRYINDEX); <span class="comment">// pop key, push value (table)</span>
- <a name="l00423"></a>00423
- <a name="l00424"></a>00424 lua_rawgeti(L, -1, ref_idx); <span class="comment">// get t[ref_idx] = value; push value</span>
- <a name="l00425"></a>00425
- <a name="l00426"></a>00426 <span class="keywordflow">if</span> (lua_isnil(L, -1)) <span class="comment">// not a valid table key</span>
- <a name="l00427"></a>00427 {
- <a name="l00428"></a>00428 lua_pop(L, 2); <span class="comment">// pop nil and table</span>
- <a name="l00429"></a>00429…
Large files files are truncated, but you can click here to view the full file