9

I want to choose an embedded scripting language that i will use on C++. It should connect a database such as Oracle. My host application is a server application. That will pass raw data to script. The script will parse and do some specific logics. Also updates database. Then script will returns raw data as result. Can you help me to choose it? Thanx

2
  • What is the problem you are trying to solve? Why do you want to do it this way, instead of just using C++ or just using ie. Python? Is speed important? Commented May 31, 2011 at 14:14
  • 2
    i want to seperate my server codes and bussiness logic. Also bussiness logic frequently changes. I already C++ all steps. I will make a core that only runs as server. Bussiness logics will be on scripts. Commented May 31, 2011 at 14:19

6 Answers 6

20

Lua is intended to be an embedded language and has a simple API. Python and Ruby are much more general purpose and are (for embedding at least) significantly more complicated. This alone would lead me to using Lua.

Sign up to request clarification or add additional context in comments.

3 Comments

Python is also intended to be an embedded language: docs.python.org/extending/embedding.html
@Alexander: Not intended. It's possible to embedd it but it was not it's initial purpose and you can see it in the effort needed to embedded it.
With boost.python it is quite easy. But you also have LuaBridge and LuaBind.
12

Lua is already mentioned and using luabind will give you a more c++ style interface.
You could also take a look at chaiscript. It was more designed to fit into c++.

2 Comments

+1: for Chaiscript. It is THAT easy to integrate Even overloading of Methods works.
+1 ditto. I have been looking for such a scripting language like that for a long time. The C api of most scripting languages is cumbersome and looks out of place even when you wrap it.
8

Save this as test.c:

#include <Python.h>

int
main(int argc, char *argv[])
{
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}

Run this command (if you have Python 2.7 installed):

gcc test.c -o test -I/usr/include/python2.7 -lpython2.7

Python has now been embedded. This took me under a minute, so I'm having a hard time understanding the claims of the "effort needed to embed it".

The example is from http://docs.python.org/extending/embedding.html.

I would suggest Python over Lua, even though Lua is also nice.

4 Comments

are there any sample project? I need oracle connectivity from script. Byte array passing to / receiving from script method.
You can connect to oracle with Python by installing the cx_Oracle module: orafaq.com/wiki/Python. Note that Lua also seem to support Oracle: keplerproject.org/luasql/manual.html
I feel like this is a non-answer. To do real embedding, we want to be able to pass objects between Python and C/C++. That requires a whole lot more work than this.
Passing objects between C/C++ and a scripting language requires work for both Lua and Python (and other solutions).
5

I've had a lot of success adding embedded scripting to my C++ applications using AngelScript. I've found it very easy to bind and the syntax to be very comfortable, but it depends on your target audience. I found Lua to be very fast and relatively easy to bind, but the syntax was a bit uncomfortable to me. AngelScript is very C/C++ like which I find very easy to understand and maintain, but to someone who spends more of their time working with CSS or HTML, might find it cumbersome and the language idioms might not translate well..

http://www.angelcode.com/angelscript/

http://www.gamedev.net/forum/49-angelcode/

Just realized I had answered a similar question here:

https://stackoverflow.com/questions/191222/what-is-a-good-embeddable-language-i-can-use-for-scripting-inside-my-software

Comments

2

TCL would be another option for an easy to embed scripting language.

personally I'd go with the scripting language you and/or whoever will be using the scripting language is most familiar with already, especially if end users will be able to run custom scripts, you will need to know what, if any, languages they are familiar with in their business domain e.g. CAD/CAM people may know TCL, gaming people may know Lua etc.

Comments

2

You might be interested in ObjectScript

ObjectScript, OS for short, is a new programming language. It's free, cross-platform, lightweight, embeddable and open-source. It combines the benefits of multiple languages, including: JavaScript, Lua, Ruby, Python and PHP. OS features the syntax of Javascripts, the "multiple results" feature from lua, syntactic shugar from Ruby as well as magic methods from PHP and Ruby - and even more!

Minimal program used ObjectScript could be like this

#include <objectscript.h>
using namespace ObjectScript;
int main(int argc, char* argv[])
{
    OS * os = OS::create(); // craete ObjectScript instance
    os->require("main.os"); // run ObjectScript program
    os->release();          // release the ObjectScript instance
    return 0;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.