Are there any statically typed, embeddable scripting languages? [closed]
Asked Answered
P

4

54

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?

Propulsion answered 4/4, 2010 at 19:3 Comment(11)
How is python loosely typed? In python many operations throw a TypeError which would simply cause undefined behavior in C++.Colene
Most of them (Python, Ruby, ...) could be considered strongly typed depending on the definition (@runtime, that is). You may want to expand on your specific strongly typed definition.Spae
Oh dear, I can see a bunfight brewing out of this one...Delicate
Python is certainly more strongly typed than C. The asker is confusing "explicitly typed" (i.e. have to specify type even when the compiler/interpreter can infer it uniquely) with "strongly typed", probably.Fumigant
Okay, my bad. Python is a bad example.Propulsion
If you mean that you want typing errors discovered at compile or load time rather than at execution time, then you should say "statically typed," whereas most scripting languages are "dynamically typed."Nickelson
Ah, yes. That is what I meant.Propulsion
In that case, I think that #2329960 is a duplicate. You might also be interested in #2265389.Glycerinate
This looks like a real question to me. The first version was just poorly phrased. And those questions don't address embedded scripting languages, which is kind of a specialized niche that's almost entirely dynamic languages.Zurkow
I am leaving this closed because it's a recommendation question.Spy
TypeScript (JavaScript with static types) that targets the JerryScript VM may be of interest to you. typescriptlang.org jerryscript.netOblivion
F
6

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

Federation answered 4/4, 2010 at 19:10 Comment(6)
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?Propulsion
@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 supportFederation
And in what world does C count as 'statically typed' ?Tampon
@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.Federation
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'...Tampon
In my book C/C++ does not qualify as "scripting" language. Admittedly, my book has no official definition of a "scripting language", but I think C/C++ is pretty far from it.Jessi
G
16

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.

Gargoyle answered 14/7, 2010 at 11:44 Comment(1)
"without worrying about C-style baggage": indeed, Angelscript seems too heavy to use to qualify as a "scripting language" to me.Jessi
F
6

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

Federation answered 4/4, 2010 at 19:10 Comment(6)
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?Propulsion
@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 supportFederation
And in what world does C count as 'statically typed' ?Tampon
@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.Federation
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'...Tampon
In my book C/C++ does not qualify as "scripting" language. Admittedly, my book has no official definition of a "scripting language", but I think C/C++ is pretty far from it.Jessi
D
4

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

Deoxygenate answered 4/4, 2010 at 19:27 Comment(0)
N
3

Haskell is statically typed. And you can probably embed ghci or hugs (both are interpreters) into another programm. But it's not easy, afaik.

Nail answered 8/11, 2012 at 23:53 Comment(3)
I have tried to use Haskell as a replacement for Python but after few attempts it was obvious that implementing anything in Haskell takes me 5 times more time than in Python. I tried to attribute this difference to my poor knowledge of Haskell but after reconsidering I have never had such lousy performance with any new language so I stick to the Python. Additionally lazy evaluation in combination with IO gives terrible unpredictable bugs. It is like grasping multi-threading when order matters but things happen out of order and in case of Haskell you do not have means of imposing order.Hambletonian
Haskell absolutely has order imposed. The order in which IO actions are sequenced for instance is the order in which they'll happen.Bilberry
late comment, but OCaml might satisfy this requirement.Scriabin

© 2022 - 2024 — McMap. All rights reserved.