views:

359

answers:

3

I am wondering if there are any statically typed, embeddable scripting languages. Python, JavaScript, etc. are great languages, but they are dynamically typed (that is, types are checked at run time). I am just wondering if anyone knows of any statically typed scripting languages that can be embedded in a C++ application?

+1  A: 

Well, there's Ch - the embeddable C/C++ interpreter

Eli Bendersky
Could you expand a bit more on Ch? Is it cross-platform? Is it released under the GPL or a different license? Is the documentation up to date?
George Edison
@George: I haven't really tried it (personally I don't see the point), but it is cross platform and free. It appears to be well documented and there's also a commercial version with (presumably) full support
Eli Bendersky
And in what world does C count as 'statically typed' ?
Jacques Carette
@Jacques: in this world, AFAIK. Types in C pertain to variables, not to values, and are determined at compile-time, which makes it statically typed.
Eli Bendersky
@Eli: Sorry, I've been working too long in languages where "lying to the compiler" (aka casting) is not considered to be a feature. So, yes, strictly speaking C can be considered typed. But most people that I know who have experienced a language where types really matter stop considering C as typed. I too long ago started thinking of C as 'portable assembler'...
Jacques Carette
+2  A: 

How about C#? Check out Mono's implementation of a C# "scripting language" REPL (http://www.mono-project.com/CsharpRepl)

Update: If you don't know what a REPL is, it's what you see when you run Python without any arguments, or irb

Paul Betts
A: 

I'd suggest you check out Angelscript. We used it on Warsow and it's pretty good. It has all the features you'd expect like classes, memory management, etc. Since it's statically typed, it can make better optimizations for you, and so the bytecode ends up faster than other scripting languages.

However, AS is not as easy to use as others like Lua, and there is only a single .zip download -- that means no .exe installers, .deb packages, .dmg or anything. Generally this is OK because you'll want to bundle AS into your project's anyways. The main difficultly compared to Lua is just that the library is a lot bigger (but has more features). Not that many people use it so it's a lot harder to find examples and help, but there are good docs so it shouldn't be all that hard to get started.

However, I would personally rather have a dynamic language for scripting. When I script an app, I want to get in there and code the crap out of it without worrying about C-style baggage. Other than AngelScript I really can't think of any others worth recommending.

Jyaan