Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: SuperLlama on January 25, 2010, 11:51:58 pm

Title: indexing a table with a wxString?
Post by: SuperLlama on January 25, 2010, 11:51:58 pm
I have a lookup table in my Squirrel script, and I'm using wxString to do some string operations. No matter what I do, though, I cannot use the wxString as a key value in the table! It gives me the error: "the index 'instance' does not exist", and the script fails. I've searched high and low for a simple tostring function, with no success. There has to be SOME way to convert a wxString into a normal Squirrel String...

EDIT:
I ended up using a foreach to go through each key and check if it's equal... but that's pretty hacky and I'd really like to know the real way to do it.
Title: Re: indexing a table with a wxString?
Post by: hovercraft on October 31, 2015, 03:51:13 am
For somebody who still searching the answer for this question :)
Right, you can use only squirrel native strings as table indexes because wxString objects are just a pointers from the squirrel's point of view.
It is possible to convert wxString to the native squirrel string this way:
function wxStr2sqStr(wxStr)
{
  local sqStr = "";
  sqStr += wxStr;
  return sqStr;
}

The inverse conversion looks a bit more complex:
function sqStr2wxStr(sqStr)
{
  local wxStr = ::wxString();
  foreach (chr in sqStr)
  {
  wxStr.AddChar(chr);
  }
  return wxStr;
}