On 1/9/07, Stewart Allen <[EMAIL PROTECTED]> wrote:
>
> local s = "HELLO"
> local wxSCD = wx.wxStringClientData(s)
> wxCLB:SetClientObject(wxSCD)
> ...
> local temp = wxCLB:GetClientObject()
> print(temp:GetData())
>
> The last line of the code shown above gives error: Attempt to call an
> invalid method 'GetData'.
>
> When I call GetClientObject it returns a object of type wxClientData(not
> wxStringClientData)
> I need to convert temp to be of type wxStringClientData in order to
> retrieve the string saved inside.
>
> How would I be able to do this?

Oops, you can't right now. There's no way to cast objects in "C" in
wxLua, which I think is generally not possible to do generically as
you can with wxObjects and DynamicCast which use a string name to get
the classinfo and properly cast it.

So... we have two options, maybe a third later.

Note that in any case wxClientData is useless in wxLua since I don't
know how we could allow arbitrary C++ subclassing in lua and we should
probably remove it. Perhaps, someone who is using wxLua as a scripting
engine in C++ could attach their own subclassed wxClientData and you
could retrieve it in wxLua, but you couldn't do anything with it.

1) Add a method GetStringClientObject() or GetClientObjectString()
that would actually return a wxStringClientData by simply casting the
wxClientData to it. If someone sent in something else and you tried to
call GetData on it would you segfault? I dunno, but it wouldn't be a
great idea to allow this.

2) Remove wxClientData from wxLua and only use wxStringClientData
everywhere. In this case you would associate the client data string to
an index into a lua table if you needed to store more data for the
item.

3) Create our own wxLuaClientData that allows you to put whatever you
want into it using something like a wxLuaObject which is almost suited
to this purpose. We do need to have a generic C++ object that in lua
you can create and put lua stuff into it. Basically it's a variant
object that can hold a string, number, bool, lua table, or C function.
We would also use this for the wxLuaTreeItem.

For now, what do you think about the first two options, both are very
easy to do. I lean towards #1 since people may want to use their own
subclassed wxClientData call GetClientObject() then call a special
function that casts the wxClientData to their version. I doubt anyone
ever will, but it's more flexible.

Regards,
    John Labenski

ps. I've been meaning to resurrect the void SetClientData(int n, void
*data) functions, but make them take integers as the void* data.
wxWidgets does not delete the void* data so if you send in an int you
can use that as a simple way to store a key to a lua table with more
info.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to