Page 1 of 3

scripting suggestions

Posted: Thu Mar 10, 2005 23:08
by lindquist
hi CE.
I've abandoned AngelScript and have been looking at LuaPlus lately. I have got a ScriptModule up and running and everything is working fine, but there's a few things.

in the CEGUI::System constructor there is a feature for a initscript. but I'm not able to use that feature since I can't register the luaplus bindings before after the new CEGUI::System call.

fx.

Code: Select all

...
LuaScriptModule* mScriptModule = new LuaScriptModule( lua_state );
system = new System( mRenderer, mScriptModule );
mScriptModule->createBindings();


so the initscript is executed before the bindings are created. not good.

I suggest to have two virtual functions in CEGUI::ScriptModule. createBindings and destroyBindings

createBindings should be called when the whole gui is initialised but before running the initscript

likewise destroyBindings should be called just before cleanup begins.

and what about a CEGUI::ScriptModule::executeString( const String& str ) method ?

anyways... I'll release something soon. But the source is somewhat messy right now.

it works by wrapper classes for the singletons and an inherited Window class with exportable functions for handling windows.

- tomas

Re: scripting suggestions

Posted: Fri Mar 11, 2005 09:36
by CrazyEddie
lindquist wrote:
I suggest to have two virtual functions in CEGUI::ScriptModule. createBindings and destroyBindings

createBindings should be called when the whole gui is initialised but before running the initscript

likewise destroyBindings should be called just before cleanup begins.

and what about a CEGUI::ScriptModule::executeString( const String& str ) method ?

All good ideas, especially createBindings and destroyBindings. I'll get these in over the weekend.

CE.

Re: scripting suggestions

Posted: Fri Mar 11, 2005 15:41
by lindquist
cool...

Re: scripting suggestions

Posted: Sat Mar 12, 2005 11:14
by CrazyEddie
These additions are now in CVS, as usual anonymous access will take a few hours to catch up...

CE.

Re: scripting suggestions

Posted: Wed Mar 16, 2005 03:25
by lindquist
Hi again.

It turned out that LuaPlus was a bit too difficult to maintain, so I've been looking at tolua++... In short it parses a "cleaned" header file and generates a .cpp file with the binding code.

though, a few additions would really make it alot easier! EventSet::subscribeEvent is a bit complicated to export when all I want to do in the script is pass a string with the function name as the subscriber. It works really well.

right now the code I need to be able to script is:

Code: Select all

subscribeEvent(name, Event::Subscriber(ScriptFunctor(subscriber_name)));
but since I can alias function-names with tolua++ it would be really convenient with C++ code like this:

Code: Select all

subscribeScriptedEvent(name, subscriber_name);


I have attached a few patches that does the trick, and fixes a few typos I spotted...

Edit:
It's because with this little change, I'm able to use the auto-generated code without any changes...

Re: scripting suggestions

Posted: Wed Mar 16, 2005 09:37
by CrazyEddie
Ok thanks I'll take a look.

I can't remember what I did in the test ScriptModule I wrote :roll:

CE.

Re: scripting suggestions

Posted: Thu Mar 17, 2005 11:39
by lindquist
I thought my last post was maybe a little unclear.

What I'm doing is exporting subscribeScriptedEvent as subscribeEvent so it's possible to write the following Lua code:

Code: Select all

local w = CEGUI.WindowManager:getSingleton():getWindow("button")
w:subscribeEvent("Clicked", "buttonClickedHandler")


instead of

Code: Select all

local w = CEGUI.WindowManager:getSingleton():getWindow("button")
w:subscribeEvent("Clicked", CEGUI.Event.Subscriber:new_local(CEGUI.ScriptFunctor:new_local("buttonClickedHandler")))


This way I don't have to export ScriptFunctor either, I really think it should be implicit anyway.

Edit:
Though if you really don't like the subscribeScriptedEvent addition, tell me, and I'll make a utility function that returns a ScriptFunctor Event::Subscriber.

fx.

Code: Select all

local w = CEGUI.WindowManager:getSingleton():getWindow("button")
w:subscribeEvent("Clicked", CEGUI.toEventSubscriber("buttonClickedHandler"))

Re: scripting suggestions

Posted: Thu Mar 17, 2005 19:49
by CrazyEddie
I looked the your proposed additions yesterday. They're all fine - and slated to be added shortly :)

I just have quite a lot of non-CEGUI stuff going on today and for the next few days, so I have not gotten around to this in my usual speedy fasion ;)

CE.

Re: scripting suggestions

Posted: Thu Mar 17, 2005 21:43
by lindquist
Hi again.

I've made a VC7.1 (it's the only thing I have) solution for my LuaGUIScriptModule that should be really easy to get started with.
There is a static-lib project with Lua 5.0.2 and tolua++1.0.4, and a static-lib LuaScriptModule. I never tried a dll version.
in the LuaScriptModule/package dir is the package definition for tolua++. make.bat updates the source file. a precompiled tolua++.exe code generator is there too.
look at the .pkg files to see what there's bindings for. It's pretty complete.

the c++ code I use is like this:

init:

Code: Select all

mLuaScriptModule = new CEGUI::LuaScriptModule( LuaManager::getSingleton().getState() );
mSystem = new CEGUI::System( mRenderer, mLuaScriptModule, (CEGUI::utf8*)"../cegui.cfg" );

exit:

Code: Select all

if ( mSystem ) delete mSystem;
if ( mLuaScriptModule ) delete mLuaScriptModule;   


here's my initscript to see how it works:

Code: Select all

-- get CEGUI singletons
local logger      = CEGUI.Logger:getSingleton()
logger:logEvent( ">>> Init script says hello" )

local system   = CEGUI.System:getSingleton()
local fontman   = CEGUI.FontManager:getSingleton()
local schememan   = CEGUI.SchemeManager:getSingleton()
local windowman   = CEGUI.WindowManager:getSingleton()

-- load schemes
schememan:loadScheme( "TaharezLook.scheme" )
schememan:loadScheme( "WindowsLook.scheme" )

-- set default mouse cursor
system:setDefaultMouseCursor( "WindowsLook", "MouseArrow" )

-- load and set default font
local font = fontman:createFont( "Arial-10.font" )
system:setDefaultFont( font )

-- create default gui sheet - root
local sheet = windowman:createWindow( "DefaultGUISheet", "root" )
system:setGUISheet( sheet )

logger:logEvent( "<<< Init script says goodbye" )


events are handled pretty naturally, one parameter is passed. An EventArgs. You can the cast to the different types of EventArgs with a few utility functions. So an eventhandler would look something like this:

Code: Select all

function event_handler( e )
   local we = CEGUI.toWindowEventArgs(e) -- new helper function
   local handler = we.window
   handler:setText( "scripted" );
   --tolua.cast(e, "const CEGUI::WindowEventArgs").window:setText("scripted") --> this would do work too
end


In classes that have public member variables, I've removed the 'd_' prefix from their names.

If this is not enough - ask away...

Edit:
the tolua++ documentation says that it's possible to call constructors by their class name fx.

Code: Select all

window:setSize(CEGUI.Size(0.2,0.5))

but there is currently a bug when using namespaces, so you have to write:

Code: Select all

window:setSize(CEGUI.Size:new_local(0.2,0.5))

Re: scripting suggestions

Posted: Fri Mar 18, 2005 21:59
by CrazyEddie
This sounds great :) I have not had a chance to look it over yet as I've been tied up. But I'll try and have a look over the weekend (and also get your patches in).

CE.

Re: scripting suggestions

Posted: Mon Mar 21, 2005 10:58
by CrazyEddie
Okay, I have tried out your script module & tolua++ bindings...

This is excellent stuff :) I'd like very much to adopt this as the 'official' lua scripting module in CEGUI. If you agree, I'd give you write access to the code once placed in CVS.

I look forward to your response :)

CE.

Re: scripting suggestions

Posted: Mon Mar 21, 2005 11:25
by lindquist
I'm glad you liked it, and I have no objections at all. So please do :)

Re: scripting suggestions

Posted: Tue Mar 22, 2005 08:02
by CrazyEddie
Cool. Thanks :)

With any luck I'll get this done over easter.

CE.

Re: scripting suggestions

Posted: Sat Mar 26, 2005 18:48
by CrazyEddie
Okay, this is now in CVS :D

It's basically unchanged at the moment, except for the following minor things:

* I added a "resourceGroup" parameter to the executeScriptFile methods so that a group does not have to be hard coded for loading the script file. This has the unfortunate side effect that the InitScript will use the default resource group.

* The VC projects are moved to be within the makefiles directory along with the others.

Currently, only VC++ 7.1 and Linux are setup, I'll do the other VC++ projects tomorrow. VC++ will retain the static lib approach, while linux builds things as libtool libraries. I have tested briefly on both platforms and all seems well :)

If you wish, I'll add you to the project with write access to the script module files. Let me know if you want this, and confirm your sourceforge username.

Thanks again.

CE.

Re: scripting suggestions

Posted: Sat Mar 26, 2005 19:24
by lindquist
Hi CE.

I would'nt mind working some more on the script module, so it would be cool with write access...

I guess I would be confirming with you anyway though... But I have a few ideas that I'm gonna try out, so I'm definately not done yet!

My sourceforge login is the same as here.

Code: Select all

lindquist


Currently I have quite alot of time available to spend coding, so I would not mind taking care of applying patches etc. if it could give you more time for CEGUI itself.

Let me know your plans (if any ;)).