473,832 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script Engine in C++

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 ?

Jul 23 '05 #1
16 4758
fe***********@g mail.com 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
Jul 23 '05 #2
fe***********@g mail.com 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
Jul 23 '05 #3
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(metho d), 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");
OutputDebugStri ngA(str.to_s()) ;
OutputDebugStri ngA("\n");
}

Google for that code to find its project.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #4
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.

Jul 23 '05 #5

<fe***********@ gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
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
Jul 23 '05 #6
fe***********@g mail.com 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
Jul 23 '05 #7
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.virtualMet hod() }

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?Fract...ine/FleaOpenGl

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #8
fe***********@g mail.com wrote in message news:<11******* *************** @o13g2000cwo.go oglegroups.com> ...
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
Jul 23 '05 #9
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.virtualMet hod() }

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.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2324
by: jianchiwei | last post by:
question: I run c:\python23\Lib\site-packages\win32comext\axscript\client\pyscript.py and it told me Registered: Python Registration of Python ActiveX Scripting Engine complete. But, when I run a asp script <%@LANGUAGE=Python%>
5
3079
by: Vince C. | last post by:
Hi. I'd like to trap ADO Recordset object events in my ASP script (either VBS or JS, no preference). I've tried (in VBS) writing a Sub rs_RecordChangeComplete( adReason, cRecords, pError, adStatus, pRecordset ) - rs being a server-side ADODB.Recordset object - but it doesn't get called whenever rs is moved (I browse it in a loop). Is there a way to catch those events from ASP?
3
8439
by: Ed Brandmark | last post by:
I have a tag of the form <SCRIPT LANGUAGE="JavaScript1.1" SRC="foo.js"..... and was wondering if this delays the loading of my page until that file foo.js downloads. It seems that if I place this in the HEAD of my document - the page will wait until it downloads. If I place it in the BODY of my document - supposedly the page
38
7174
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } function makeArray0() {
1
2505
by: Carl Waldbieser | last post by:
Has anyone had any experience embedding a CPython engine in a .NET application? In the COM/ActiveX world, it was pretty easy to use Mark Hammond's win32 modules to create a script engine component that you could expose other COM objects to, but I was not sure how I would go about doing something similar in a .NET environment. For example, something like: .... .NET Application code ... 'Create Foo object. set Foo = New Foo("baz")...
9
1725
by: sam.s.kong | last post by:
Hello! I have a JavaScript code like the following. <script> var s = "</script>"; ....
1
3012
by: Hardy Wang | last post by:
Hi all, Anybody knows where can I find some information about script engine theory? I have the requirement: Our product has some template files, and there placeholder/variabled embedded inside template (like %CurrentTime%, %HoursRemaining% and so on). There are also some other variables (like %Coupon%) whose value is based on values of other variables. For example
1
2714
by: Andrus | last post by:
I'm creating WinForms ERP application. This application need to run custom scripts in may places like: retrieving list of invoices before adding invoice before saving invoice after saving invoice before posting invoice after posing etc.
3
11304
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10498
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9319
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5623
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3077
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.