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

Poll

Which scripting language would you like to see?

Lua
13 (61.9%)
GameMonkey
2 (9.5%)
Python
4 (19%)
Pawn
0 (0%)
Squirrel
1 (4.8%)
Other (Please tell which)
1 (4.8%)

Total Members Voted: 21

Voting closed: August 11, 2009, 03:08:58 am

Author Topic: Scripting module for SFML  (Read 11831 times)

0 Members and 1 Guest are viewing this topic.

EClaesson

  • Newbie
  • *
  • Posts: 13
    • MSN Messenger - emanuel.claesson@gmail.com
    • View Profile
    • Email
Scripting module for SFML
« on: August 11, 2009, 03:08:58 am »
I have some plans of writing a simple scripting module for SFML.
I need one myself fo a project, so i thougt that i just as well could share it.

I have a question for you though..
Which scripting language would you like to see in the module?

Lua - Easy to use, fast and relativly good features.
GameMonkey - C-like syntax, and quite small. (Small is good)
Python - Nice syntax, a bit "huge" though.
Pawn - C-like syntax. Fast. Has to be compiled though.
Squirrel - Syntax similiar to Lua and Python. Good features.
Suggest - If you have any suggestions about a language, please let me know!  :wink:
//Emanuel Claesson

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Scripting module for SFML
« Reply #1 on: August 11, 2009, 08:21:37 am »
I can't really think of a generic scripting module. The mentioned scripting languages all provide interfaces, already. Python, for example, can even be used with Boost.

EClaesson

  • Newbie
  • *
  • Posts: 13
    • MSN Messenger - emanuel.claesson@gmail.com
    • View Profile
    • Email
Scripting module for SFML
« Reply #2 on: August 11, 2009, 09:54:50 am »
I know it's not the most necessary module to write, but i just want to write a simple wrapper. This will be used for a custom PostFX system (if i can get it fast enough).  :wink:
//Emanuel Claesson

_seb_

  • Newbie
  • *
  • Posts: 16
    • View Profile
Scripting module for SFML
« Reply #3 on: August 12, 2009, 10:30:24 am »
ChaiScript

From http://www.chaiscript.com/faq

Why use ChaiScript?
The current defacto-standard of embedded scripting is Lua. Lua is a great, simple language that serves its purpose well. However, it is written in pure ANSI C. While this gives it outstanding portability, it greatly limits its ability to interact well with C++.

ChaiScript, on the other hand, was designed from the ground up with integration with C++ in mind.

To effectively use Lua, a language designed for embedding, with C++, you must use a preprocessor or meta compiler such as toLua++ or SWIG. While these tools are helpful, they do add unnecessary complexity to your application when you did not specifically need Lua and instead were searching for a simple way to provide scripting capabilities to your application.

Similarly, boost::python, while avoiding the meta-compiler, adds the complexity and size of libpython and python module system.

ChaiScript has no meta-compiler, no library dependencies, no build system requirements and no legacy baggage of any kind. At can work seamlessly with any C++ functions you expose to it. It does not have to be told explicitly about any type, it is function centric.

With ChaiScript you can literally begin scripting your application by adding three lines of code to your program and not modifying your build steps at all.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scripting module for SFML
« Reply #4 on: August 12, 2009, 11:08:48 am »
Quote
ChaiScript has no meta-compiler, no library dependencies, no build system requirements and no legacy baggage of any kind.

Not completely true. It apparently depends on boost, which is a huge dependency. And if you have boost you can easily get wrappers for other script languages (luabind, boost::python, ...), at least as powerful as the ChaiScript API.

Quote
With ChaiScript you can literally begin scripting your application by adding three lines of code to your program and not modifying your build steps at all.

Same here. The "Getting started" page starts with "Getting boost".

Apart from that, it seems to be a nice language with a nice C++ API :)
Laurent Gomila - SFML developer

EClaesson

  • Newbie
  • *
  • Posts: 13
    • MSN Messenger - emanuel.claesson@gmail.com
    • View Profile
    • Email
Scripting module for SFML
« Reply #5 on: August 12, 2009, 03:20:50 pm »
It looks like it's easy to embed. But i'll get mad at it as it is a c/javascript-like syntax.. without semicolons. And i agree with Laurent when it comes to the boost part.

And i can't manage to find any reference of the "standard library", if there even are one. No, i did not download anything. Just clicked around the website.
//Emanuel Claesson

lefticus

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • http://blog.emptycrate.com
Scripting module for SFML
« Reply #6 on: August 12, 2009, 07:36:42 pm »
Hi, I'm one of the co-developers of ChaiScript so I thought I would answer some of the questions coming up here.

Yes, the syntax is C and javascript-like. Semicolons are optional. I personally do tend to use them when I'm programming, out of habit.

There is a page in the documentation about the standard library: http://www.chaiscript.com/node/3.

The standard library is intentionally kept very simple. ChaiScript is meant quite simply as a tool for scripting C++ applications. As such, we made the ability to add new features extraordinarily simple and kept the built-ins low. I have not used LuaBind, but from what I know it comes the closest to ChaiScript, but still does not quite hit the same mark.

Example, if you want to add the C standard library functions fabs and abs to the ChaiScript runtime, and give them the same name, allowing the runtime to choose the appropriate function to call:

Code: [Select]

ChaiScript chai;
chai.add(fun(&abs), "abs");
chai.add(fun(&fabs), "abs");

chai.call("print(abs(-5.2))");


(The above represents an almost complete C++ application using ChaiScript, all that is missing is main and the include).

Regarding "no external dependencies": ChaiScript is a header only library. Yes, it does rely on parts of boost, but only the header-only pieces of it. There are no runtime dependencies. So, yes, the building process does require that you have the boost headers available, it actually does not require you to build or install any part of the boost libraries.

None of the other examples that are mentioned can make that claim, they all at least require the language libraries itself (libpython.so, liblua.so, etc).

The language was really designed around my personal usage requirements. I wanted something that provided the same functionality that Lua does, for embedding, but I wanted it designed for C++ (as opposed to C, as Lua is) and I wanted to avoid the overhead of something like SWIG, which I have used in many projects myself already.

I'm glad that there seems to be some interest in the language, anyhow, so thanks _seb_ for mentioning it in the first place. Let me know if anyone has any questions I can help with.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scripting module for SFML
« Reply #7 on: August 12, 2009, 08:01:22 pm »
Hi :)

As far as I remember, luabind also uses the boost headers, and is header-only itself. And it can do the same stuff as ChaiScript -- the only limitation is that Lua doesn't support function overloading (as far as I remember, again).

Actually, I think that every library which smartly binds C++ to script needs boost, unless you want to waste precious weeks of your life writing crazy template stuff.
Laurent Gomila - SFML developer

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Scripting module for SFML
« Reply #8 on: August 12, 2009, 09:57:37 pm »
Quote from: "Laurent"
Hi :)

As far as I remember, luabind also uses the boost headers, and is header-only itself. And it can do the same stuff as ChaiScript -- the only limitation is that Lua doesn't support function overloading (as far as I remember, again).

Actually, I think that every library which smartly binds C++ to script needs boost, unless you want to waste precious weeks of your life writing crazy template stuff.


Look at the first and third features: http://www.rasterbar.com/products/luabind/docs.html#features

IMO, if you program C++ and don't use Boost and the STL extensively, you are doing something wrong  :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scripting module for SFML
« Reply #9 on: August 12, 2009, 10:55:28 pm »
Quote
Look at the first and third features

I think they talk about function overload on the C++ part.
Laurent Gomila - SFML developer

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Scripting module for SFML
« Reply #10 on: August 13, 2009, 05:18:20 am »
Quote from: "Laurent"
Quote
Look at the first and third features

I think they talk about function overload on the C++ part.


They are talking about overloaded C++ functions that can be used from Lua, isn't that what you meant?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scripting module for SFML
« Reply #11 on: August 13, 2009, 07:41:12 am »
Quote
They are talking about overloaded C++ functions that can be used from Lua

With two different names on the Lua side.

lefticus was talking about the opposite thing: two different C++ functions bound to the same name in script.
Laurent Gomila - SFML developer

EClaesson

  • Newbie
  • *
  • Posts: 13
    • MSN Messenger - emanuel.claesson@gmail.com
    • View Profile
    • Email
Scripting module for SFML
« Reply #12 on: August 13, 2009, 10:36:18 am »
I must say tha ChaiScript seems like it would be very easy to implement, and i do like the syntax. And as i have the Boost library avilable, it's no problem for me. I dont know if i even need to write a custom scripting module for sfml, as ChaiScript basically has what i planned to write. :)
//Emanuel Claesson

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Scripting module for SFML
« Reply #13 on: August 14, 2009, 02:57:10 pm »
Quote from: "Laurent"
Quote
They are talking about overloaded C++ functions that can be used from Lua

With two different names on the Lua side.

lefticus was talking about the opposite thing: two different C++ functions bound to the same name in script.


Nope, same name both in Lua as in C++:

Code: [Select]
module(L)
[
    def("f", (int(*)(const char*)) &f),
    def("f", (void(*)(int)) &f)
];


And two different functions bound to the same name (should) work as well.

teto

  • Newbie
  • *
  • Posts: 35
    • View Profile
Scripting module for SFML
« Reply #14 on: August 14, 2009, 04:11:09 pm »
I've begun a month ago a lua bind of SFML with luabind. I'm using it so it works. I've not bound everything, just what I needed but this is quite enough to have been able to create a functioning GUI. I split the binds by library since I intended at some point to share it ( I even posted a topic on the French forum about this ).

also it is embedded in my 3D engine which parse events and distribute them to my own LUA functions.

Luabind is very effective and clean but I will take a look at chai.

As for games, I've read that squirrel would be the best choice. It is designated for games, C++ ( I believe it to be a fork of lua created for Far cry ?) but I chose LUA because of the amount of documentation around it.
See you net cow-boy ...