Script Engine in C++

Discussion in 'C++' started by fernandez.dan@gmail.com, Mar 21, 2005.

  1. Guest

    Hey I'm sorry if this is not the appropriate news group for this
    question. I was wondering if anyone has any recommendation for
    embbedding a script engine in a c++ application. I want to feed my C++
    application scripts which based on the script would create C++ objects
    and call the appropriate methods.

    At the moment I created a simple interpreter within our C++ aplication
    that we can feed our custom scripts. The interpreter is primitive and
    it lacks alot of functionality that is why I am looking at other
    alternatives.

    I looked at spidermonkey to embed in my c++ application but it seems a
    little cumbersome dealing with C++ objects. Does anyone have any other
    recommendations?
     
    , Mar 21, 2005
    #1
    1. Advertising

  2. wrote:
    > Hey I'm sorry if this is not the appropriate news group for this
    > question. I was wondering if anyone has any recommendation for
    > embbedding a script engine in a c++ application. I want to feed my C++
    > application scripts which based on the script would create C++ objects
    > and call the appropriate methods.
    >
    > At the moment I created a simple interpreter within our C++ aplication
    > that we can feed our custom scripts. The interpreter is primitive and
    > it lacks alot of functionality that is why I am looking at other
    > alternatives.
    >
    > I looked at spidermonkey to embed in my c++ application but it seems a
    > little cumbersome dealing with C++ objects. Does anyone have any other
    > recommendations?
    >


    Python should probably work for most platforms.

    V
     
    Victor Bazarov, Mar 21, 2005
    #2
    1. Advertising

  3. wrote:

    > Hey I'm sorry if this is not the appropriate news group for this
    > question. I was wondering if anyone has any recommendation for
    > embbedding a script engine in a c++ application. I want to feed my C++
    > application scripts which based on the script would create C++ objects
    > and call the appropriate methods.
    >
    > At the moment I created a simple interpreter within our C++ aplication
    > that we can feed our custom scripts. The interpreter is primitive and
    > it lacks alot of functionality that is why I am looking at other
    > alternatives.
    >
    > I looked at spidermonkey to embed in my c++ application but it seems a
    > little cumbersome dealing with C++ objects. Does anyone have any other
    > recommendations?



    I do not know much on this area but some useful links are:


    UnderC, a compact C++ interpreter:
    http://home.mweb.co.za/sd/sdonovan/underc.html

    Ch, an embeddable C/C++ interpreter for cross platform scripting,
    numerical computing and 2D/3D plotting: http://www.softintegration.com

    CINT, C/C++ interpreter: http://root.cern.ch/root/Cint.html

    ROOT, Data Analysis Framework: http://root.cern.ch



    Definitely you will find something here:

    More C++ libraries: http://www.trumphurst.com/cpplibs/cpplibs.phtml




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Mar 21, 2005
    #3
  4. Phlip Guest

    fernandez.dan wrote:

    > I was wondering if anyone has any recommendation for
    > embbedding a script engine in a c++ application.


    All of Lua, Python, Ruby, etc. are written with embedding in mind. Lua
    hardly has any other presence.

    > I want to feed my C++
    > application scripts which based on the script would create C++ objects
    > and call the appropriate methods.


    Here's a wrapper for Ruby's VALUE object:

    class
    rbValue
    {
    public:

    rbValue(VALUE nuV = Qnil):
    v(nuV)
    {}

    rbValue(char const * gv):
    v(Qnil)
    {
    assert(gv);
    assert('$' == gv[0]); // documentation sez this is optional. We
    don't agree
    v = rb_gv_get(gv);
    }

    operator VALUE() const { return v; }
    rbValue &operator =(VALUE nuV) { v = nuV; return *this; }

    rbValue
    fetch(char const * tag)
    {
    return funcall("fetch", 2, rb_str_new2(tag), Qnil);
    }

    rbValue
    fetch(int idx)
    {
    return funcall("fetch", 2, INT2FIX(idx), Qnil);
    }

    rbValue
    fetch(size_t idx)
    {
    return funcall("fetch", 2, INT2FIX(idx), Qnil);
    }

    VALUE *
    getPtr()
    {
    assert(T_ARRAY == TYPE(v));
    return RARRAY(v)->ptr;
    }

    long
    getLen()
    {
    assert(T_ARRAY == TYPE(v));
    return RARRAY(v)->len;
    }

    rbValue
    getAt(long idx)
    {
    assert(idx < getLen());
    return RARRAY(v)->ptr[idx];
    }


    rbValue
    operator[](long idx)
    {
    return getAt(idx);
    }

    bool isNil() { return Qnil == v; }

    double to_f()
    {
    assert(T_FLOAT == TYPE(v) || T_FIXNUM == TYPE(v));
    return NUM2DBL(v);
    }

    char const * to_s()
    {
    assert(T_STRING == TYPE(v));
    return STR2CSTR(v);
    }

    rbValue
    funcall (
    char const * method,
    int argc = 0,
    VALUE arg1 = Qnil,
    VALUE arg2 = Qnil,
    VALUE arg3 = Qnil
    )
    {
    return rb_funcall(v, rb_intern(method), argc, arg1, arg2, arg3);
    }

    rbValue
    iv_get(char const * member)
    {
    VALUE iv = rb_iv_get(v, member);
    return iv;
    }

    void
    iv_set(char const * member, VALUE datum)
    {
    rb_iv_set(v, member, datum);
    }

    void
    iv_set(char const * member, int datum)
    {
    iv_set(member, INT2FIX(datum));
    }

    private:
    VALUE v;

    }; // a smart wrapper for the Ruby VALUE type

    Call its members like this:

    void
    push(rbValue xyzIn)
    {
    rbValue str = xyzIn.funcall("inspect");
    OutputDebugStringA(str.to_s());
    OutputDebugStringA("\n");
    }

    Google for that code to find its project.

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Mar 21, 2005
    #4
  5. Guest

    Thanks for the input. I looked at Python and how it can be implemented
    in a C++ by using SWIG. What do you think about Ruby? It is a pure
    object oriented scripting language but I'm am newbie to that language.
    I'm wondering if it is easier to access C++ objects over Python or
    Javascript? Also looked at lua but it seems a bit old.
     
    , Mar 21, 2005
    #5
  6. Walter Guest

    <> wrote in message
    news:...
    > Hey I'm sorry if this is not the appropriate news group for this
    > question. I was wondering if anyone has any recommendation for
    > embbedding a script engine in a c++ application. I want to feed my C++
    > application scripts which based on the script would create C++ objects
    > and call the appropriate methods.
    >
    > At the moment I created a simple interpreter within our C++ aplication
    > that we can feed our custom scripts. The interpreter is primitive and
    > it lacks alot of functionality that is why I am looking at other
    > alternatives.
    >
    > I looked at spidermonkey to embed in my c++ application but it seems a
    > little cumbersome dealing with C++ objects. Does anyone have any other
    > recommendations?


    DMDScript (a javascript implementation) can be embedded in C++ applications.
    There's also a version for embedding in D programming language applications.

    -Walter
    www.digitalmars.com/dscript DMDScript
     
    Walter, Mar 21, 2005
    #6
  7. wrote:
    > Thanks for the input. I looked at Python and how it can be implemented
    > in a C++ by using SWIG. What do you think about Ruby? It is a pure
    > object oriented scripting language but I'm am newbie to that language.
    > I'm wondering if it is easier to access C++ objects over Python or
    > Javascript? Also looked at lua but it seems a bit old.
    >


    Since I participated, I feel obliged to respond. I don't think about
    Ruby, so the answer is "nothing". As to JavaScript (or should we call it
    "LiveScript"?), I have also no idea what capabilities it provides. I know
    that our products provide scriptability through Python and that there are
    other possibilities. If there were a single scripting language that
    covered all needs and satisfied all requirements, we wouldn't have such
    a variety of choices. So, it's totally up to you to see which one suits
    you. And let's not convert the short enumeration of a few options into
    a full-blown discussion on scripting languages since it would be off-topic
    here.

    V
     
    Victor Bazarov, Mar 21, 2005
    #7
  8. Phlip Guest

    fernandez.dan wrote:

    > Thanks for the input. I looked at Python and how it can be implemented
    > in a C++ by using SWIG.


    You can also bond with Python using Boost, or using Python's raw C-style
    API. SWIG is an elaborate adapter system to bond any object with any other
    object in any language. We are not amused.

    > What do you think about Ruby?


    It competes successfully with both Perl and Smalltalk, wisely leaving behind
    the worst of both. My velocity using Ruby is triple that of any other
    language.

    Compare traversing a heterogeous list in Ruby to, say, Java:

    myList.each { |node| node.virtualMethod() }

    How many tokens would Java require to claw its way to the same (common)
    result?

    > It is a pure
    > object oriented scripting language but I'm am newbie to that language.
    > I'm wondering if it is easier to access C++ objects over Python or
    > Javascript?


    The "object" is relatively irrelevant. The point of objects is virtual
    methods. If you have a binding layer then you have opaque methods anyway, so
    they either dispatch or they don't. And otherwise "objects" are just
    syntactic sugar.

    > Also looked at lua but it seems a bit old.


    Lua is super-fast, and has block closures like Ruby. Its speed comes at the
    price of a screwey object model that makes implementing objects
    non-intuitive. And its speed makes it the leading contender for the
    scripting layer for high-end video games.

    Here's an oblique example of Lua driving a videogame:

    http://flea.sourceforge.net/gameTestServer.pdf

    And here's an example of Ruby in essentially the same role:

    http://www.rubygarden.org/ruby?FractalLifeEngine/FleaOpenGl

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Mar 22, 2005
    #8
  9. Basil Guest

    wrote in message news:<>...
    > Hey I'm sorry if this is not the appropriate news group for this
    > question. I was wondering if anyone has any recommendation for
    > embbedding a script engine in a c++ application. I want to feed my C++
    > application scripts which based on the script would create C++ objects
    > and call the appropriate methods.
    >
    > At the moment I created a simple interpreter within our C++ aplication
    > that we can feed our custom scripts. The interpreter is primitive and
    > it lacks alot of functionality that is why I am looking at other
    > alternatives.
    >
    > I looked at spidermonkey to embed in my c++ application but it seems a
    > little cumbersome dealing with C++ objects. Does anyone have any other
    > recommendations?



    Hello.

    Open Basic this is realization of the interpreter of language Basic.

    http://www.mktmk.narod.ru/eng/ob/ob.htm

    Open Basic (OB) is realization of the interpreter of language Basic.
    OB is developed for embed to user application as a script language.
    User may attach (connect) user function to Open Basic execution
    system.
    The user functions can be written on C/C++, assembler or others
    languages.
    The user functions can receive parameters from the Basic-program and
    return results to Basic-program.
    Program interface of user functions allows determine type and order
    of parameters at run-time.
    OB realizes a subset of commands of language Basic.
    OB it is written completely on C++ and it is realized as a class with
    a name ob_obasic.
    OB supports data of three types: floating point, signed integer, and
    string and arrays of these types.
    OB has multithread-safe code.

    Now OB have library for GCC 3.2.2, BCB 6.0, MSVC 7.

    For use OB need only one library for appropriated compiler and 6
    header files:

    mstore.h - policy
    mvect.h - vector
    mlist.h - list
    mstack.h - stack
    mhash.h - hash-table
    ob.h - main header file of Open Basic


    Open Basic have IDE for program debug.

    Integrated development environment for Open Basic (IDE OB) is
    intended for support of debugging programs of interpreter Open Basic.

    http://www.mktmk.narod.ru/eng/ide_ob/ide_ob.htm

    IDE OB can be an example for integration of interpreter Open Basic
    for
    OS Windows.

    IDE OB is not a part of interpreter Open Basic.
    Interpreter Open Basic can use without IDE OB.

    IDE OB gives usual service of the debugging environment:
    - Edit the text of programs
    - Loading programs into interpreter (some modes)
    - Start of program in the interpreter
    - Stop program
    - Step-by-step execution of program
    - Animate execution of program
    - Breakpoints (on interpreter level, do not support IDE OB)
    - Viewing and updating variables ("Watch" window)
    - Viewing diagnostic messages of the interpreter ("Messages" window)
    - Support of operators PRINT and INPUT ("I/O Terminal" window)

    IDE OB is written on Borland C++ Builder 6.0 (BCB 6.0).

    Sincerely Yours
    Basil
     
    Basil, Mar 22, 2005
    #9
  10. Phlip wrote:
    >>What do you think about Ruby?

    >
    >
    > It competes successfully with both Perl and Smalltalk, wisely leaving behind
    > the worst of both. My velocity using Ruby is triple that of any other
    > language.
    >
    > Compare traversing a heterogeous list in Ruby to, say, Java:
    >
    > myList.each { |node| node.virtualMethod() }
    >
    > How many tokens would Java require to claw its way to the same (common)
    > result?


    I, too, now consider Ruby my scripting language of choice.
    Integrating it with C++ needs the usual setjmp/longjmp exception
    support hacks as with any other scripting languages that support
    setjmp/longjmp exceptions. But the extensions API is probably the
    best I've seen.
     
    Asfand Yar Qazi, Mar 24, 2005
    #10
  11. <> schrieb im Newsbeitrag
    news:...
    > Hey I'm sorry if this is not the appropriate news group for this
    > question. I was wondering if anyone has any recommendation for
    > embbedding a script engine in a c++ application. I want to feed my
    > C++
    > application scripts which based on the script would create C++
    > objects
    > and call the appropriate methods.
    >
    > At the moment I created a simple interpreter within our C++
    > aplication
    > that we can feed our custom scripts. The interpreter is primitive
    > and
    > it lacks alot of functionality that is why I am looking at other
    > alternatives.
    >
    > I looked at spidermonkey to embed in my c++ application but it seems
    > a
    > little cumbersome dealing with C++ objects. Does anyone have any
    > other
    > recommendations?


    I've seen some guy, who wrote a script engine based on a gcc
    installation shipped with the program. So, you just #inlcude
    "my_plugin.h" and have all the interfaces ready, then click a "create
    plugin" script that gcc's a .dll (or a .so on Linux/unix) - fast and
    easy to implement. Very good idea I think. Especially for a game,
    where performance is everything.
    -Gernot
     
    Gernot Frisch, Mar 24, 2005
    #11
  12. Phlip Guest

    Asfand Yar Qazi wrote:

    > I, too, now consider Ruby my scripting language of choice.
    > Integrating it with C++ needs the usual setjmp/longjmp exception
    > support hacks as with any other scripting languages that support
    > setjmp/longjmp exceptions. But the extensions API is probably the
    > best I've seen.


    ? I just use the 'protected' versions of functions.

    I remain curious what happens to reality when you throw a C++ exception
    from a C++ layer, thru the Ruby layer, and into a catch in the calling
    C++ layer. Probably fireworks...

    --
    Phlip
     
    Phlip, Mar 24, 2005
    #12
  13. Phlip wrote:

    > ? I just use the 'protected' versions of functions.
    >
    > I remain curious what happens to reality when you throw a C++ exception
    > from a C++ layer, thru the Ruby layer, and into a catch in the calling
    > C++ layer. Probably fireworks...



    I think applause. :)



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Mar 25, 2005
    #13
  14. On Tue, 22 Mar 2005 00:51:22 +0000, Phlip wrote:

    > Compare traversing a heterogeous list in Ruby to, say, Java:
    >
    > myList.each { |node| node.virtualMethod() }
    >
    > How many tokens would Java require to claw its way to the same (common)
    > result?


    This is so far off-topic that I can't even see C++ from here, but:

    for (NodeType node : myList) {
    node.virtualMethod ();
    }

    Looks like 15 tokens to me. Two more than the Ruby example. (Admittedly,
    this is a new feature, and the idiom it replaces required far more tokens.)

    HTH, Owen
     
    Owen Jacobson, Mar 26, 2005
    #14
  15. Phlip Guest

    Owen Jacobson wrote:

    > This is so far off-topic that I can't even see C++ from here,


    So what?

    > but:
    >
    > for (NodeType node : myList) {
    > node.virtualMethod ();
    > }
    >
    > Looks like 15 tokens to me. Two more than the Ruby example.

    (Admittedly,
    > this is a new feature, and the idiom it replaces required far more

    tokens.)

    Props. And I know not to challenge Java, or its experimental
    implementations, to show block closures, co-routines, generics, etc.

    The important, topical goal here is understanding the friction between
    static typing (like C++) and dynamic typing. The latter provides a
    higher development velocity, at greater risk to your execution
    velocity. We will see how Java can continue to compete.

    --
    Phlip
     
    Phlip, Mar 27, 2005
    #15
  16. Phlip Guest

    Phlip, Mar 27, 2005
    #16
  17. If you targeting your application only for Windows platform, then you
    can easily go with the scripting support provided by Windows. By
    implementing a small COM object you'll get:

    * Possibility of scripting in any language for which user registered a
    scripting engine in the system (JScript and VBScript are there by
    default and there is compatible scripting engine for Perl)
    * Possibility to create and use inside the script any COM object with
    dispatch interface registered in the system.
    * Provide access to objects inside your application.
    * Let user write event handlers for the events your objects have.

    There was a nice article on CodeProject on how to embed Windows
    scripting engine support into your application. Works great.

    wrote:
    > Hey I'm sorry if this is not the appropriate news group for this
    > question. I was wondering if anyone has any recommendation for
    > embbedding a script engine in a c++ application. I want to feed my C++
    > application scripts which based on the script would create C++ objects
    > and call the appropriate methods.
    >
    > At the moment I created a simple interpreter within our C++ aplication
    > that we can feed our custom scripts. The interpreter is primitive and
    > it lacks alot of functionality that is why I am looking at other
    > alternatives.
    >
    > I looked at spidermonkey to embed in my c++ application but it seems a
    > little cumbersome dealing with C++ objects. Does anyone have any other
    > recommendations?
    >
     
    Yuriy Solodkyy, Mar 27, 2005
    #17
  18. steumarok

    Joined:
    Sep 26, 2011
    Messages:
    1
    steumarok, Sep 26, 2011
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    735
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. jianchiwei

    asp script engine registrition

    jianchiwei, Apr 28, 2004, in forum: Python
    Replies:
    2
    Views:
    450
    Mark Hammond
    Apr 29, 2004
  3. Carl Waldbieser
    Replies:
    1
    Views:
    452
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Nov 24, 2005
  4. Replies:
    1
    Views:
    387
    Sybren Stuvel
    Apr 10, 2006
  5. Sasha
    Replies:
    3
    Views:
    612
    Sasha
    May 22, 2007
Loading...

Share This Page