Author Topic: indexing a table with a wxString?  (Read 6917 times)

SuperLlama

  • Guest
indexing a table with a wxString?
« 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.
« Last Edit: January 26, 2010, 12:16:49 am by SuperLlama »

Offline hovercraft

  • Single posting newcomer
  • *
  • Posts: 2
Re: indexing a table with a wxString?
« Reply #1 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;
}
« Last Edit: November 01, 2015, 03:35:29 pm by hovercraft »