Scripting language for C/C++?
Asked Answered
D

11

15

Is there a scripting language for C++ (like perl) which can be used for rapid development and use some tool which can convert into C/C++ program to get higher performance for deployment?

EDIT:
Based on some commented, let me clarify the question. I should be able to convert script into C/C++ program or binary without modifying my script.

Denn answered 3/10, 2009 at 14:44 Comment(7)
@rjoshi, perhaps you need to clarify. I assumed the opposite of @Mike that you wanted to host a scripting language in a C++ application. I've done that for Windows with the VBScript engine, so perhaps it was my experience as my bias.Refresher
I want to do a quick prototype in scripting language for development and should be able to deploy for high performance so I was wondering some to can convert script into C/C++ program for deployment.Denn
@rjoshi: Please do not comment on your own question. Please update your question. Commenting on your own question is silly -- you own the question. You can fix it to clarify things.Tatia
@S. Lott: Thanks for letting me know. I am new to this forum. I will follow your advice.Denn
@Mike - Do you have a source for your statement that any part of Perl is written in C++?Bilek
@Chris download latest perl source, "$find . -name "*.cpp"Guenna
@Guenna - It's not the latest, but for 5.10 it only uses C++ for NetWare and Symbian OS. I suppose that counts.Bilek
P
26

With a C/C++ interpreter you can use C/C++ as a scripting language.

Note: So far, I have tried only Ch and CINT. I have added ccons and UnderC to make the list more complete.

Portentous answered 3/10, 2009 at 14:56 Comment(4)
those links are very, very interesting, thanks for sharing with us! I didn't think that there is actually a possibility to create c++ scripts :)Nepheline
What is "C/C++"? Do these interpreters support C, or C++, or both?Skelp
@KeithThompson Ch an CINT support both C and C++. CINT says it "covers most of ANSI C (mostly before C99) and ISO C++ 2003". And Ch claims to implement a superset of C and a subset of C++.Portentous
CINT is superseded by cling. And cling covers C++ fully (and not "mostly" like CINT).Ferdie
N
10

You may try Lua quite often used with C++ in games industry. It has a small memory footprint and is quite mature, has a great library... just give it a try.

hm... I do not understand what you want to achieve: do you want to find a scripting language that will somehow, magically be converted into c++ source? Or what you really want is just an option to create an executable from the script? If the latter - then you may try py2Exe.

Nepheline answered 3/10, 2009 at 15:0 Comment(2)
"Small foot print" is a relative term... Lau requires more memory than some systems I would like to use it on have.Galata
For embedded development (and alike) where every byte of memory is valuable, using any language that comes with its own VM may not be the best solution (I assume). You haven't specified what you want to use the scripting language for, on what kind of platform, what were the limitations... It was quite hard to guess ;) And if you would like to compare performance of various languages: shootout.alioth.debian.orgNepheline
J
4

Anybody interested in a scripting language that is (mostly) very similar to C++, may want to take a look at angelscript (ZLIB):

The AngelCode Scripting Library, or AngelScript as it is also known, is an extremely flexible cross-platform scripting library designed to allow applications to extend their functionality through external scripts. It has been designed from the beginning to be an easy to use component, both for the application programmer and the script writer.

Efforts have been made to let it call standard C functions and C++ methods with no need for proxy functions. The application simply registers the functions, objects, and methods that the scripts should be able to work with and nothing more has to be done with your code. The same functions used by the application internally can also be used by the scripting engine, which eliminates the need to duplicate functionality.

For the script writer the scripting language follows the widely known syntax of C/C++ (with minor changes), but without the need to worry about pointers and memory leaks. Contrary to most scripting languages, AngelScript uses the common C/C++ datatypes for more efficient communication with the host application.

For more info, check out: http://www.angelcode.com/angelscript/sdk/docs/manual/index.html

Jaime answered 7/3, 2010 at 21:54 Comment(0)
S
2

Many projects combine e.g. C++ and Python -- see for example boost.python.

I prefer R and use the Rcpp interface from R to C++.

Either case gives you your scripting language for prototyping and easy 'glue' to C++ for performance.

Skim answered 3/10, 2009 at 14:49 Comment(0)
L
2

pawn

pawn is a simple, typeless, 32-bit extension language with a C-like syntax. A pawn "source" program is compiled to a binary file for optimal execution speed. The pawn compiler outputs P-code (or bytecode) that subsequently runs on an abstract machine. Execution speed, stability, simplicity and a small footprint were essential design criteria for both the language and the abstract machine.

This language is very simular to c syntax, so anyone that has done any c++,c,c#,java will be able to read it and its simplyfied so none coders can read it to. This language is currently used all around, among other places scripting against halflife 1 and halflife2 servers.

Lifeguard answered 3/10, 2009 at 15:58 Comment(1)
/me loves my pawn, and the AMX guys have done some INSANE things with the language.Debutante
I
2

There is a new package Chaiscript which is designed for C++. It's relatively new and not completely stable yet.

Itemized answered 4/10, 2009 at 10:3 Comment(0)
C
1

For Python, I sometimes find psyco useful. Not sure if there is any equivalent for perl though.

When choosing a language for a task, I find it more useful to choose the language most suited for the job. If the job asks for more performance than a scripting language can provide under normal conditions, it is usually better to just switch than to bend over backwards to try to make your code fast.

Chrisom answered 3/10, 2009 at 15:1 Comment(1)
I agree with your comment but problem is you are doing quick prototype and won't know the performance requirements until product becomes successful and performance becomes bottleneck.Denn
C
0

The question could be interpreted different ways...

If you have already coded a part of your application in C++ and need to add modules or scripts, that you want to add in the C++ code eventually for improved performance, you could use Qt which is a solid, very complete multi-platform framework.

It includes support for scripts (ECMAScript, the standardized version of Javascript), from which you can access your C++ objects if you need to. It also provides support for plug-ins.

With that approach, you can even proceed in three steps,

  • first do some tests in Javascript,
  • then code the base of your application in C++ and still use a part in scripts (for example if you need to try different algorithms),
  • and finally port everything, or at least the critical parts, in C++.

Another option is to embed a Python interpreter in your code, although that will probably require more work.

Choli answered 3/10, 2009 at 15:33 Comment(0)
B
0

I'm not sure I understand your question but if your looking to implement your own scripting language which could interface with your c++ code you can take a look at boost::spirit. You just have to tell it your grammar and you have your scripting language doing whatever you tell it to in c++. You specify your grammar using c++ operators making it very easy and intuitive.

That's what I currently used for my recent needs and it looks like it will do the job just fine. You have full access to your c++ objects when specifying your grammar and your user can have a very simple language to learn (compared to CINT where the language would be c++ itself).

Compile time are a little slow right now but if you don't need to implement a very complex language it should be manageable (I wouldn't like to see the compile time for something like c++). Also documentation is a little lacking for the newest version (and the most up-to-date version is a little hard to find) but it's relatively easy to use so it might be worth a check, depending on your needs.

Barrack answered 4/10, 2009 at 3:13 Comment(0)
C
0

You could code using D programming language as both a script or a fast compiled output.

here is an article that talks in detail about D and its advantages "The Case for D"

Carreno answered 23/7, 2013 at 18:36 Comment(0)
D
0

Cling is an interpreter for c++ cling

Dunbar answered 29/9, 2016 at 19:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.