Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

891486 Posts in 33545 Topics- by 24778 Members - Latest Member: sleepyzombie

June 19, 2013, 08:32:29 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Scripting
Pages: [1] 2
Print
Author Topic: Scripting  (Read 2245 times)
theman515
Level 0
**


The code... the code!!


View Profile WWW Email
« on: January 24, 2012, 04:09:44 PM »

hello everyone,

so i've gotten to the point where I need scripting in my game. I'm developing in C++ and was wondering what language would be easiest to pass inheritance classes to and how to do it? see i would want something like:
Code:
class foo:public bar
{
    public:
       foo(int nume){num=nume;}
       int getNum(){return num;}
       void setNum(int nume){num=nume;}
    private:
       int num;
};

where the num would be set in C++ then the python or perl script would accept the pointer of the class and be able to mess around with it. I tried boost.python but all the documentation is horrible and no other language seems to have what i need.

Any suggestion would be awesome.

Thanks in advance  Gentleman
Logged
eigenbom
Level 10
*****



View Profile WWW
« Reply #1 on: January 24, 2012, 09:47:30 PM »

Hey, Lua's pretty good ... along with Luabind you can do...

register your class to Lua (c++)
Code:
module(L)[
  class_<foo>("foo")
  .def(constructor<int>())
  .property("num", &foo::getNum, &foo::setNum)
];

in lua use it
Code:
f = foo()
f.num = 3
Logged

theman515
Level 0
**


The code... the code!!


View Profile WWW Email
« Reply #2 on: January 24, 2012, 10:25:05 PM »

oh so lua can handle C++ classes? i was under the impression that they could not. thanks!
Logged
eigenbom
Level 10
*****



View Profile WWW
« Reply #3 on: January 24, 2012, 10:59:05 PM »

oh so lua can handle C++ classes? i was under the impression that they could not. thanks!

Lua has tables which, with a bit of work, can kind of act like classes. Luabind does all this wrangling for you. Mind you, Luabind uses some crazy c++ voodoo, so if you're not adept in c++ it mightn't be worth the trouble. ToLua++ is an alternative but I haven't used that.
Logged

Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #4 on: January 27, 2012, 03:40:26 AM »

More suggestions: look up the Falcon programming language and AngelScript. They're both more curly brace languages that are as easy to integrate as Lua.
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
Xecutor
Level 1
*


View Profile Email
« Reply #5 on: January 27, 2012, 06:23:15 AM »

From ease of use point of view http://www.chaiscript.com/ is probably the best.
But it uses black magic of boost.

Falcon is not curly brace. But it's good one.
Logged
Evan Balster
Level 10
*****


dreaming close to metal


View Profile WWW Email
« Reply #6 on: January 27, 2012, 05:17:28 PM »

After some debating I settled on Angelscript for my own stuff.  Not sure you can extend C++ classes with script ones, though.
Logged

Infinite Blank, SoundSelf, Cave Story+, Wreath
voice, accordion, mandolin, oboe (?!)
Game audio programming consultant.
<plaid/audio> 0.2: opensource audio framework
randomnine
Level 1
*


View Profile WWW
« Reply #7 on: January 27, 2012, 06:06:40 PM »

Python and SWIG can do what you want. You can even create a class on the Python side that inherits from a C++ class, have it override virtual functions etc and (with the 'directors' feature enabled in SWIG) it'll all work nicely. There's support in there for all kinds of magic.

It's messy to implement, sure, but there's plenty of documentation. If you go down that route I recommend just making time and reading for a while before diving in.
Logged

Evan Balster
Level 10
*****


dreaming close to metal


View Profile WWW Email
« Reply #8 on: January 27, 2012, 06:40:54 PM »

The big downside with python is that (generally) the user needs to have it installed.  Something without a standard library is a bit harder to code in, but way easier to distribute and build with.
Logged

Infinite Blank, SoundSelf, Cave Story+, Wreath
voice, accordion, mandolin, oboe (?!)
Game audio programming consultant.
<plaid/audio> 0.2: opensource audio framework
rivon
Level 10
*****



View Profile
« Reply #9 on: January 28, 2012, 08:43:59 AM »

Still it's easier IMO than distributing Java with your game...
Logged
Geeze
Level 5
*****


Totally.


View Profile
« Reply #10 on: January 28, 2012, 09:22:59 AM »

Yeah. Using python is just matter of including one dll. At least Construct classic does that if one uses python scripting.
Logged

increpare
Guest
« Reply #11 on: January 28, 2012, 09:28:52 AM »

The big downside with python is that (generally) the user needs to have it installed.  Something without a standard library is a bit harder to code in, but way easier to distribute and build with.
Have you embedded python as a scripting language before yourself?  The only software I've ever had to install python to use are ones distributed as raw python scripts, but I've used plenty of pieces of software that use python as an embedded scripting language (Blender is the only one that comes to mind right now, admittedly) and never have been asked to install it.
Logged
Klaim
Level 10
*****



View Profile WWW
« Reply #12 on: January 28, 2012, 02:51:45 PM »

Also, Boost.Python does help embedding Python in C++ code - meaning you don't need to install anything too, it's one of the poitns of embedding scripting languages...


But Python embedded is expensive on memory and execution time, compared to languages that are made from the beginning to be embedded in C++, like ChaiScript and Falcon, or are made to be embedded from C embedded software like Lua.

Python might be better choice when you run on PC (or hardware with far enough resources) or you're builing a "tool".

Personally, for games where I need something as expressive as Python but as embeddable as Lua or ChaiScript, I use Falcon (but it's in a major rewrite currently so it's not stable yet).

I use ChaiScript when I just need to quickly setup a scripting language and don't bother much about the scripting syntaxe, because ChaiScript is so easy to just plug in your game code (requires Boost, but header-only library).

I use Lua when I target high constraints hardware (mobiles, consoles).

I've never used AngelScript.
Logged

http://www.klaimsden.net | Game : NetRush | Digital Story-Telling Technologies : Art Of Sequence
rivon
Level 10
*****



View Profile
« Reply #13 on: January 28, 2012, 03:23:12 PM »

I've just taken a look at ChaiScript and I have to say it looks very nice and easy to embed...
AngelScript though is also great.
Logged
theman515
Level 0
**


The code... the code!!


View Profile WWW Email
« Reply #14 on: January 28, 2012, 07:18:01 PM »

a question on chaiscript, i've embedded it and i have boost installed but im getting errors on the boost thread
Code:
||=== Pew Pew Adventure, Debug ===|
::~thread_specific_ptr()]+0x65)||undefined reference to `_imp___ZN5boost6detail12set_tss_dataEPKvNS_10shared_ptrINS0_20tss_cleanup_functionEEEPvb'|
)]+0x85)||undefined reference to `_imp___ZN5boost6detail12set_tss_dataEPKvNS_10shared_ptrINS0_20tss_cleanup_functionEEEPvb'|
::get() const]+0xd)||undefined reference to `_imp___ZN5boost6detail12get_tss_dataEPKv'|
||=== Build finished: 3 errors, 0 warnings ===|
does anyone have any idea what that means?
Logged
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic