I have modified EvaluateExpr for newer versions of lua.
This makes global variables display properly.
Expression does not want to work and I really have no idea why.
The code is right must be some string conflict problems.

bool wxLuaDebugTarget::EvaluateExpr(int exprRef, const wxString 
&strExpr) // FIXME - check this code
{
    wxString strResult(wxT("Error"));
    int      nReference = LUA_NOREF;

    EnterLuaCriticalSection();
    {
        lua_State* L = m_wxlState.GetLuaState();

        int nOldTop = lua_gettop(L);
        if (wxStrpbrk(strExpr.c_str(), wxT(" ~=<>+-*/%(){}[]:;,.\"'")) 
!= NULL)
        {
            // an expression

            wxLuaCharBuffer charbuf(strExpr);
            int nResult = luaL_loadbuffer(L, charbuf.GetData(), 
charbuf.Length(), "debug");

            if (nResult == 0)
                nResult = lua_pcall(L, 0, LUA_MULTRET, 0);  // call main

            if (nResult != 0)
                wxlua_pushwxString(L, wxlua_LUA_ERR_msg(nResult));

            else if (lua_gettop(L) == nOldTop)
                lua_pushliteral(L, "OK");

            nReference = m_wxlState.wxluaR_Ref(-1, 
&wxlua_lreg_refs_key);
            lua_settop(L, nOldTop); // throw out all return values
        }
        else
        {
            lua_Debug ar        = INIT_LUA_DEBUG;
            int  stack_level    = 0; // 0 is the current running 
function
            bool variable_found = false;

            while (lua_getstack(L, stack_level++, &ar) != 0)
            {
                int stack_index = 1; // 1 is the first local stack index
                wxString name = lua2wx(lua_getlocal(L, &ar, 
stack_index));

                while (!name.IsEmpty())
                {
                    if (strExpr == name)
                    {
                        nReference = m_wxlState.wxluaR_Ref(-1, 
&wxlua_lreg_refs_key);
                        lua_pop(L, 1);
                        variable_found = true;
                        break;
                    }

                    lua_pop(L, 1);
                    name = lua2wx(lua_getlocal(L, &ar, ++stack_index));
                }

                if (variable_found)
                    break;
            }
                        lua_settop(L, nOldTop); // the table of globals.

            if (!variable_found)
            {
#if LUA_VERSION_NUM < 502
                  lua_pushvalue(L, LUA_GLOBALSINDEX);
                  lua_pushnil(L);
                  while (lua_next(L, -2) != 0)
                  {
                      if (lua_type(L, -2) == LUA_TSTRING)
                      {
                          wxString name = lua2wx(lua_tostring(L, -2));
                          if (strExpr == name)
                          {
                              nReference = m_wxlState.wxluaR_Ref(-1, 
&wxlua_lreg_refs_key); // reference value
                              lua_pop(L, 2);    // pop key and value
                              variable_found = true;
                              break;
                          }
                      }

                      lua_pop(L, 1);  // removes 'value';
                  }
#else
                                lua_getglobal(L, strExpr);
                                if (lua_type(L, -1) != LUA_TNONE)
                                {
                    nReference = m_wxlState.wxluaR_Ref(-1, 
&wxlua_lreg_refs_key); // reference value
                                }
                                lua_pop(L, 1);

#endif
            }
            lua_settop(L, nOldTop); // the table of globals.
        }

        if ((nReference != LUA_NOREF) && 
m_wxlState.wxluaR_GetRef(nReference, &wxlua_lreg_refs_key))
        {
            m_wxlState.wxluaR_Unref(nReference, &wxlua_lreg_refs_key);

            int wxl_type = 0;
            wxString value;
            wxLuaDebugData::GetTypeValue(L, -1, &wxl_type, value);

            strResult.Printf(wxT("%s : %s"), wxluaT_typename(L, 
wxl_type).c_str(), value.c_str());

            lua_pop(L, 1);
        }
    }
    LeaveLuaCriticalSection();

    return NotifyEvaluateExpr(exprRef, strResult);
}


Good luck
Andre


------------------------------------------------------------------------------
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to