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

Login with username, password and session length

 
Advanced search

1075922 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:46:04 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Scripting
Pages: [1] 2
Print
Author Topic: Scripting  (Read 2604 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
*****


I live in this head.


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

Creativity births expression.  Curiosity births exploration.
Our work is as soil to these seeds; our art is what grows from them...


Wreath, SoundSelf, Infinite Blank, Cave Story+, <plaid/audio>
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
*****


I live in this head.


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

Creativity births expression.  Curiosity births exploration.
Our work is as soil to these seeds; our art is what grows from them...


Wreath, SoundSelf, Infinite Blank, Cave Story+, <plaid/audio>
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
eclectocrat
Level 5
*****


Most of your personality is unconscious.


View Profile
« Reply #15 on: January 29, 2012, 02:53:18 AM »

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?

LOL I love C++ template hissy fits.

Have you linked with the boost thread specific storage library? Looks like there are some missing symbols having to do with tss.
Logged

I make Mysterious Castle, a Tactics-Roguelike
rivon
Level 10
*****



View Profile
« Reply #16 on: January 29, 2012, 07:19:55 AM »

There aren't in fact any templates. It's just automatically created wrapper code which tends to have cryptic names. SWIG does the same magic.
Logged
Klaim
Level 10
*****



View Profile WWW
« Reply #17 on: January 29, 2012, 11:14:48 AM »

Yeah no template there.

On Visual Studio, boost will automatically try to link itself so you don't have to set it yourself.
On GCC you have to know that some boost libraries require linking, like boost.thread, boost.filesystem and some others.

If it don't fix your problem, then check that you do have the lib files. If not you can build them or install them.
Logged

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


The code... the code!!


View Profile WWW Email
« Reply #18 on: January 29, 2012, 03:34:26 PM »

ah yup compiling it into a dll fixed it. thanks guys! you were a huge help!
Logged
Klaim
Level 10
*****



View Profile WWW
« Reply #19 on: January 30, 2012, 02:29:26 AM »

If you're not using the static version of boost libs, then don't forget to put the required dlls in the binary repository before shipping Wink

I know it's obvious but I prefer to take care of this early.
Logged

http://www.klaimsden.net | Game : NetRush | Digital Story-Telling Technologies : Art Of Sequence
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic