Jump to content


Photo

Luaplus


  • This topic is locked This topic is locked
14 replies to this topic

#1 rincewind

rincewind

    Programming Department

  • Xenocide Programming Department
  • 541 posts

Posted 09 December 2005 - 05:07 AM

Hi,

just stumbled across this: http://luaplus.org/t...aPlus Home Page

Someone interested in checking it out and see how much conversion effort it would take? I really like the debugger stuff. Also luabind is not really active as far as I see.

Rincewind
Posted Image

I love boost!!! The next best thing since the invention of C++.

#2 reist

reist

    Programming Department

  • Xenocide Programming Department
  • 130 posts

Posted 09 December 2005 - 06:32 AM

Can it even be used on anything other than windows? I didn't find anything recent except this, and that's not very reassuring:
http://gpwiki.org/fo...opic.php?t=1888

Anyway, luabind is active. They're latest cvs has files as recently changed as 4 days ago.
The latest cvs should also be compilable on anything (and will need some changes in xenocide code to use too).
I'm going to build gcc 3.4.5 and 4.0.2 and check with them.

#3 rincewind

rincewind

    Programming Department

  • Xenocide Programming Department
  • 541 posts

Posted 09 December 2005 - 06:35 AM

Can it even be used on anything other than windows? I didn't find anything recent except this, and that's not very reassuring:
http://gpwiki.org/fo...opic.php?t=1888

Anyway, luabind is active. They're latest cvs has files as recently changed as 4 days ago.
The latest cvs should also be compilable on anything (and will need some changes in xenocide code to use too).
I'm going to build gcc 3.4.5 and 4.0.2 and check with them.

<{POST_SNAPBACK}>


Good point. (Nevertheless, we do need some debugging thingy once we have more complex AI scripts in there).

But LuaPlus doesn't have a nice C++-Classes binding anyway, so luabind seems better there.

Rincewind
Posted Image

I love boost!!! The next best thing since the invention of C++.

#4 Serge

Serge

    Project Leader: UFO 2000

  • Xenocide Programming Department
  • 785 posts

Posted 09 December 2005 - 07:40 AM

With just a few macro definitions, LuaPlus can provide a nice binding for C++ classes (but don't know if that's nice from your POV :) ). But actually ufo2000 uses not all the LuaPlus but only LuaPlusCallDispatcher. And at least LuaPlusCallDispatcher is portable enough (ufo2000 works in Win32, Linux, FreeBSD, MacOS). C++ binding looks like this:
   LUA_REGISTER_CLASS(L, Soldier);
    LUA_REGISTER_CLASS_METHOD(L, Soldier, reset_stats);
    LUA_REGISTER_CLASS_METHOD(L, Soldier, set_attribute);
    LUA_REGISTER_CLASS_METHOD(L, Soldier, set_name);
    LUA_REGISTER_CLASS_METHOD(L, Soldier, set_skin_info);
    LUA_REGISTER_CLASS_METHOD(L, Soldier, find_place);

    LUA_REGISTER_CLASS(L, Place);
    LUA_REGISTER_CLASS_METHOD(L, Place, add_item);
    LUA_REGISTER_CLASS_METHOD(L, Place, destroy_all_items);
    
    LUA_REGISTER_FUNCTION(L, pck_image);
    LUA_REGISTER_FUNCTION(L, pck_image_ex);
    LUA_REGISTER_FUNCTION(L, png_image);
    LUA_REGISTER_FUNCTION(L, png_image_ex);

Just my 2 cents as a happy LuaPlus user :) Though if I was going to start from scratch, I would probably try squirrel now. Just for consistency as its syntax is close to C++
ufo2000 development team
http://ufo2000.sourceforge.net

#5 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 09 December 2005 - 08:23 AM

If we would port script binding then why not drop Lua at all and move to best in-game scripting engine I've ever played with named Squirrel? It has reference counted memory manager (instead of garbage collector, which in fact our build of lua doesn't use, since I provided us with LuaRC which is reference counted Lua version; btw, luarc is used by LuaPlus), has Eclipse plugin so you get syntax highlighting, then you have remote debugger (which is also integrated in this Eclipse plugin), you get true classes and instances support (which are only emulated in Lua using Lua's tables), you get integer type (Lua supports only float numbers), and very C-like syntax. Then you have 2 (or even 3) methods of binding C++ to Squirrel, one being luabind-like (called Squadd) and the second looks more like what Sarge showed (called SqPlus). Remote debugging ability itself is enough to switch, but that's only my opinion... and my 2 cents ;)

Guyver

PS. Guess who's back? :D

Edited by guyver6, 09 December 2005 - 08:24 AM.

Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#6 red knight

red knight

    Xenocide Project Leader

  • Xenocide Inactive
  • 3,310 posts

Posted 09 December 2005 - 08:40 AM

Glad you are back ;) we will talk soon on MSN. =b

Debbuging is very important for anything you do, so lets research options. Even though I wouldnt focus too much on that, I prefer senior developers to work on other more pressing issues.

Greetings
Red Knight
Sourceforge Nick: flois - Federico Andres Lois
Visit my blog at: flois.blogspot.com

Posted Image

Pookie cover me, I am going in.

#7 rincewind

rincewind

    Programming Department

  • Xenocide Programming Department
  • 541 posts

Posted 09 December 2005 - 10:42 AM

Glad you are back ;) we will talk soon on MSN.  =b

Debbuging is very important for anything you do, so lets research options. Even though I wouldnt focus too much on that, I prefer senior developers to work on other more pressing issues.

Greetings
Red Knight

<{POST_SNAPBACK}>


Great to have you back guyver (even better when you see now familiar faces again :-) ).
I like the squirrel feature list. I also agree with red knight on priorities, nevertheless, it would be nice if there's someone who could investigate this as having better scripting support helps debugging a lot, especially with the startup times we currently have in debug-builds.

Rincewind
Posted Image

I love boost!!! The next best thing since the invention of C++.

#8 Garo

Garo

    Programming Department

  • Xenocide Programming Department
  • 119 posts

Posted 28 December 2005 - 01:36 PM

Squirrel looks interesting, taking some look over it now :)

I don't know if you have made any progress from where I left the lua code, but all my experiences from lua have been.. umm.. really bad so far. It has poor debugging support, no real class support at all (the class support is done with luaplus and it's more a hack, not a real language feature), lot of easy pitfalls with local/global variables, garbace collection instead of reference counting (ok, the don't-member-the-name patch fixes this) which makes working with classes and their destructors a pain in the donkey and so on...

So in my opinion, we should really consider changing from lua while we still can.


- Garo

Edited by Garo, 28 December 2005 - 01:39 PM.


#9 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 28 December 2005 - 02:41 PM

The drawback of Squirrel is that it don't have advanced binding library like luabind is for Lua. We do need something like that, I looked deeply into Squirrel's SqPlus and it's nothing special, I managed to fast prototype CEGUI scripting module for Squirrel and it was working pretty well, but then I discovered the amount of work that has to be done in binding CEGUI classes to Squirrel and left it there. Rincewind also did some prototyping with Squirrel in Xenocide and what I saw he had some problems with binding our shared pointers and strings using SqPlus.

In the mean time, I though that I could take a look at Python again. It's very powerful scripting language, really easy to use and learn (I'm writting small time-saving utilities in python for a long time, the next utility I'll make will change our license header in Xenocide files to new one). When I left it 1,5 year ago in favor of Lua, I had lot's of problems debugging scripts, even getting python's output to show in console. After googling a little more than before (and grabbing python's source) I've found out really easy way to redirect all python's interpreter output (namely sys.stdout and sys.stderr) to wherever I like. Since I had a python's code the more I looked into it, the more stuff I saw there that wasn't needed for embedding it in game. Things like looking 6 times for a directory where python's library is or things like modifing python behavior depending on env vars and windows registry entries. I removed it all, zipped python's lib, did some magic and... voila, I have really nice Python 2.4.2 dll with one .zip file which can't be hacked with windows registry and enviromental variables.

So, what about binding to python? Boost.Python. Enough said.

Debugger? I've found 2 remote debuggers, for what I tested one of them works perfectly and is really nice.

I prototyped a test case to see if python output can really be that easily redirected and I must say that it works like a charm.

I'm now in a phase of adopting pyogre's CEGUI python bindings so I can test CEGUI with python, but since that's actively developed I expect not much problems with it.

So, how about using python as our scripting language? :)

PS. Some game references are: Battlefield 2 (uses Python for server scripting), Civilization 4 (uses Python for everything, binding done with Boost.Python).
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#10 Garo

Garo

    Programming Department

  • Xenocide Programming Department
  • 119 posts

Posted 28 December 2005 - 02:49 PM

Haven't yet looked at Boost.Python, but after a quick look over Squirrel, I also think that it isn't all that what we need.

I haven't coded with Python for ages, but I also like the language. One of the greatest need for us is good thread/coroutines support, so that we can run dozens of task scripts simultaneously with yielding. Lua has it, and I've made some good tech-demos with it and I think it's really important for us :)

Have to take a look over Boost.Python next =)

- Garo

#11 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 28 December 2005 - 03:01 PM

Haven't yet looked at Boost.Python, but after a quick look over Squirrel, I also think that it isn't all that what we need.

I haven't coded with Python for ages, but I also like the language. One of the greatest need for us is good thread/coroutines support, so that we can run dozens of task scripts simultaneously with yielding. Lua has it, and I've made some good tech-demos with it and I think it's really important for us :)

Have to take a look over Boost.Python next =)

- Garo

<{POST_SNAPBACK}>

Python has a construct called Generator, which is basicly what Lua's coroutines are. I'd like you to work with me on putting whether scripting language we'll choose to better use. This implies using CEGUI's EventType element to subscribe event handlers. This would look sth like that in .layout file:
<EventType Name="MouseClick" Function="Xenocide.Transaction().buyCurrent()" />
This says more or less that for a MouseClick event, CEGUI will call Python code specified in Function attribute. No more subscribeEvent etc hardcoded in C++ and recompiling every little change. How do you like it? :)

Edited by guyver6, 28 December 2005 - 03:01 PM.

Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#12 Garo

Garo

    Programming Department

  • Xenocide Programming Department
  • 119 posts

Posted 28 December 2005 - 04:06 PM

Python has a construct called Generator, which is basicly what Lua's coroutines are. I'd like you to work with me on putting whether scripting language we'll choose to better use. This implies using CEGUI's EventType element to subscribe event handlers. This would look sth like that in .layout file:

<EventType Name="MouseClick" Function="Xenocide.Transaction().buyCurrent()" />
This says more or less that for a MouseClick event, CEGUI will call Python code specified in Function attribute. No more subscribeEvent etc hardcoded in C++ and recompiling every little change. How do you like it? :)

<{POST_SNAPBACK}>


Sounds good to me :)

Another thing, I was crawling over Boost.Python documentation, and I didn't find any good note about functors/callbacks.

In lua, I could create a C++ functor, which is dynamically binded into a lua function and later just call the functor() to execute the lua function. It's like a callback'ing lua from C++.

With Boost.Python, I know that I could simply evaluate (for example) command string "Xenocide.Transaction().buyCurrent()", but that's not very efficient. A better way (IMO) would first evaluate the Xenocide.Transaction().buyCurrent(), create a functor and pass the actual instance/pointer to this function into the functor, so that somewhere inside CEGUI/Xenocide layers clicking the button would simply execute something like this:
try {
  if (callback_function.isValid()) {
    callback_function(); // this would jump into python interpreter (or schedule the execution for later) and execute whatever has been binded. in .layout
  }
} catch (SomePythonBindingException & e) {

}

Got what I mean? =)

- Garo

#13 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 28 December 2005 - 05:56 PM

That luabind::functor you're refering to was not good design decision. They removed luabind::functor in CVS some time ago. Why?

Simply because function in Lua is an object type, just like numeric, string or a table. In current luabind implementation you're using luabind::object to hold functions, and if you want to call that function, you have luabind::call_function or something like that. This way they unified object interface.

The same thing is with Boost.Python. Methods and functions are normal boost::python::objectS, which you can call using boost::python::call() function. You just need to get an boost::python::object referencing python function to be able to call it later.
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#14 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 28 December 2005 - 06:00 PM

Oh, and refering to your example that's what I'm going to do when event hits (more or less). I want to compile what's in Function="" to bytecode (Python bytecode) and cache it. Once an event occures I'll simply eval (that's how Python calls running compiled bytecode) that.
Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#15 Garo

Garo

    Programming Department

  • Xenocide Programming Department
  • 119 posts

Posted 29 December 2005 - 05:46 AM

When surfing around the net, I found this: http://harkal.sylphi...ackless-python/

worth a reading I think :)

- Garo