Page 1 of 1

Lua and listbox

Posted: Sat May 21, 2011 13:17
by Dalon
Hi, it's me again :D

I have another question about CEGUI listboxes in lua. I have the following code...

Code: Select all

function ChatWindow_AddText(text)
    local chatLog = CEGUI.toListbox(wndMgr:getWindow("ChatLog"))    -- I use this as a global variable but just to let you know how I initialise that variable in lua is declare it in the function as local

    ...

   chatLog:addItem(...)
end


I end up with an error: CEGUI::ScriptException in file Game.cpp(336) : Could not call event function: [string "Scripts/Windows/ChatWindow.lua"]:76: attempt to call method 'addItem' (a nil value)

Also I would like to know, what to give as parameter. I know, in cpp I should give a pointer to an instance of for example a CEGUI::ListboxTextItem. I tried this in Lua...

Code: Select all

chatLog:addItem(CEGUI.ListboxTextItem:new(text))


... and ended up with a message that new is a nil value here :D

Re: Lua and listbox

Posted: Sat May 21, 2011 13:34
by Kulik
Well I would guess that the window you are retrieving is not a Listbox so you can't cast it to a Listbox.

There is a big difference between ItemListbox and Listbox, maybe you have mistaken those?

Re: Lua and listbox

Posted: Sat May 21, 2011 13:38
by Dalon
Hi,

okay I didn't read correctly and was too quick posting here. You were right... i casted the wrong window object -.-"

And I found these very useful ".pkg" files in the cegui source folder which contain some informations about the classes. So it sais:

/***********************************************************************
ListboxTextItem

The constructor is not exportet, instead a helper function is
available (CEGUI.createListboxTextItem).

I decided to do it like this to avoid any possible memory issues
with allocating from Lua.
***********************************************************************/


But thanks :) Now it works ^^