0
101 Jan 30, 2007 at 02:33

I have decided to go “Data-Driven”-design with my project and use a script language for game code. I’ve looked at Lua, Python, Ruby, AngelScript and UnrealScript (seems great, shame it’s not free). Except for the annoying lack of inheritance, AngelScript seems good.

I’m mainly looking for a C++/Java syntax-like (strongly-typed and object-oriented) language that binds well with C++, suggestions are appreciated.

Thank you.

#### 34 Replies

0
101 Jan 30, 2007 at 03:34

Any reason why Lua doesn’t cut it?

0
102 Jan 30, 2007 at 08:17

Lua isn’t strongly-typed and some people don’t grok it’s object-oriented capabilities. Both completely bogus points in my humble opinion. Of course, I just finished writing a another quick application in Lua and found it as enjoyable as ever. ;)

0
101 Jan 30, 2007 at 12:44

Tcl works fine for game scripts too.

Why bother having a “strongly-typed and object-oriented” as your scripting language when you’ve already got a one in C++.

I’d recommend using DLL instead of scripts if that [c++] is what you want, and allow the ability to reload your code.

0
101 Jan 30, 2007 at 15:27

@eddie

Any reason why Lua doesn’t cut it?

As monjardin mentioned not strongly-typed (which I seek) and it has some annoying quirks (no explicit variable declaration, index from 1?). Other than that it seems like a fast, light and mature language.
@dave_

Why bother having a “strongly-typed and object-oriented” as your scripting language when you’ve already got a one in C++. I’d recommend using DLL instead of scripts if that [c++] is what you want, and allow the ability to reload your code.

DLLs are not cross-platform and require compilation (which I want to avoid).

0
101 Jan 30, 2007 at 15:54

Squirrel is a decent language, although it isn’t strongly typed. It’s basically a flavor of lua with some c++ features. The binding is pretty easy using SqPlus and I’ve heard jkBind is pretty good too.

0
101 Jan 30, 2007 at 16:00

You could always write your own :) : http://www.peroxide.dk/tuts_scr.shtml

0
101 Jan 30, 2007 at 17:14

Writing your own scripting language isn’t that hard. I got a prototype of the compiler and interpreter of my object-oriented (UnrealScript like) language ready within 2 months.

You may try out by yourself.

cu,
chris

0
101 Jan 30, 2007 at 23:28

Torque Scripting is very powerful, also look up DM Language for Byond.

0
101 Jan 31, 2007 at 00:33

@monjardin

Lua isn’t strongly-typed and some people don’t grok it’s object-oriented capabilities. Both completely bogus points in my humble opinion. Of course, I just finished writing a another quick application in Lua and found it as enjoyable as ever. ;)

Ah. I don’t think he mentioned strongly-typed/OO before he edited it again, hence my question.

Too bad - Lua’s a great language. And strongly-typed is really over-rated in a scripting language: IMHO.

0
101 Jan 31, 2007 at 10:09

@eddie

And strongly-typed is really over-rated in a scripting language: IMHO.

You miss the point that strongly typed languages help the programmer to catch some errors at compiletime instead of runtime and therefore reducing the cost of runtime-debugging. The sooner you find errors the better.

cu,
chris

0
101 Jan 31, 2007 at 10:19

There is an answer to that: Test driven development

0
101 Jan 31, 2007 at 10:41

@dave_

There is an answer to that: Test driven development

Well, there’re many other strategies that are far better than that. Strongly typeness is one of it.

cu,
Chris

0
101 Jan 31, 2007 at 11:02

That’s not really the current consensus. In fact I’d go as far to say that is nonesense. For an fairly complex system you end up having to break the typing anyway! (using things like RTTI, reflection or similar)

Test driven development can be applied to both strong and weak typed, but with it, it doesn’t matter if you’ve got strong or weak typing. If you write your tests properly you wont get stupid runtime errors.

Dynamic languages are gaining quite a bit of momentum at the moment.

I’ve just thought that you might not actually realise what weak typing actually is. Its not a complete absence of typing. It just allows implicit conversions more easily. It is actually possible for a weakly typed language to be type safe.

0
101 Jan 31, 2007 at 11:29

There’s a lot misunderstanding about strong vs weak vs loose typeness. C++ is not a strong typed language nor is java. But many people here (see the posts above) think that they are. I believe that what many people really mean is typed vs untyped. So I take their definition for not confusing them.

And as for test driven develeopment you need to write lots of test cases that do not enshure, that everyone uses your classes and methods as they’re meant to be. Those tests show only that all those stuff is working in the context of your test environment not necessarily in the context of the final complex software product.

cu,
chris

0
101 Jan 31, 2007 at 11:38

How does that argue in favour of strong typing?
You might be against TDD but you haven’t argued for strong typing.

0
101 Jan 31, 2007 at 12:03

I thought that the benefits of strong typeing are well known!

• no implicit conversions that may result in behaviour not intended by the programmer.
• classes/methods have to be used as they are meant to be. If a function expecteds an integer you are forced to use that type. You’re forced to use an explicit conversion otherwise that visualizes what’s truly going on.
• In a truly strong-typed language you’re also forced to declare the range of a type and *useness* of a variable. This way nobody can accidentally pass a ‘null’ reference when it’s not allowed. Or pass wrong array sizes, etc. This makes software overall more safe and reduces debugging costs a lot.
• You can’t lie by hacking around with address-operators and unsafe c-conversions making code less readable and errorprone.
• Software inspections are easier und much more powerfull what in turn safes you more time and money.

ok I’m now going to eat something. Back in a while…

cu,
chris

0
101 Jan 31, 2007 at 15:55

@Christian Weis

You miss the point that strongly typed languages help the programmer to catch some errors at compiletime instead of runtime and therefore reducing the cost of runtime-debugging. The sooner you find errors the better. cu,
chris

I never said I didn’t understand the benefits of a strongly typed language – simply that it’s over-rated in a scripting language.

First let me start off explaining the way I work with scripts – I generally use runtime *as* compile-time. I love being able to reload scripts at runtime, and use that as valuable debugging time to make sure that everything’s positioned correctly, or flowing in the right way, etc. I mention this not because it’s super relative to the debate, but simply because it’s how I use scripting, and therefore the difference between compile time and runtime is much smaller – although it doesn’t argue for/against strong/weak/dynamic typing, it does impact the way I work.

As for my point about strongly-typed being over-rated: I can appreciate how that thought might scare someone who’s used to a strongly-typed system: “Why wait until the failure reaches further down your code, rather than at the spot where a compiler can catch it?”. And I agree in part - it’s nicer to have your errors sooner rather than later. But to be honest, it doesn’t buy you much. It can make you feel comfortable that the type is indeed what you want it to be, but after all my years in working with languages like Lua, Python, JavaScript – I’ve never found myself wanting that in those languages.

Perhaps it’s because, like _dave alluded to, I find unit tests a much more important part of checking my code than strong-typing ever will be in those languages. I’d much rather catch those errors in a domain semantic way – a way that has much more meaning to you as a programmer – rather than a very elementary compiler semantic one.

But that’s just been my experience.

0
101 Jan 31, 2007 at 16:50

AngelScript or c-script

ains.

0
101 Jan 31, 2007 at 23:15

@eddie

Perhaps it’s because, like _dave alluded to, I find unit tests a much more important part of checking my code than strong-typing ever will be in those languages. I’d much rather catch those errors in a domain semantic way – a way that has much more meaning to you as a programmer – rather than a very elementary compiler semantic one.

:yes: :worthy: :yes:
@Christian Weis

I thought that the benefits of strong typeing are well known!

They are well known, but they’re not generally thought of as useful for a scripting language. Most useful scripting languages lean towards the weaker side of things to enable rapid prototyping.

0
101 Feb 01, 2007 at 02:08

@eddie

strongly-typed is really over-rated in a scripting language: IMHO.

strongly-typed is really under-rated in a scripting language, IMHO.

Besides being less error-prone it makes clearer and potentially faster code, all of which could be nice.

0
165 Feb 01, 2007 at 04:10

I agree - I really hate seeing things like

function foo (bar, baz)


I have no idea what type bar and baz are supposed to be. Numbers, strings, some ADT or object? Of course, one can document this in comments, but as we all know comments can get out of date or incorrect. Static typing (I’ll use this term since ‘strong typing’ is sort of vague) isn’t just a compile-time check on (a limited aspect of) program correctness, it’s also means of documenting code, where the compiler can automatically verify that the documentation is correct.

0
102 Feb 01, 2007 at 04:32

I understand the value of both and usually prefer static typing as well. However, for the cases where I use Lua it’s usually not necessary and would just slow thing down. I mean Lua only has one number type anyway (usually double unless you change it). So, everything is either a number, a string, a table or user data. Of course, Lua was meant as a configuration language. If the OP is looking for something beyond that then it seems completely fair to favor static, strong or whater-you-call it typing.

Altough, World of Warcraft seems to have done just fine with Lua for managing their UI. Others have used it much more extensively (e.g. Far Cray, Impossible Creatures, Baldur’s Gate, Homeworld 2, et cetera.

EDIT: Just to make a point… :devil:

char *foo (int bar, double baz)


How is this much better? I still don’t have a clue what the function does, much less any idea if it is working correctly without a unit test. ;)

0
101 Feb 01, 2007 at 05:12

@monjardin

EDIT: Just to make a point… :devil:

char *foo (int bar, double baz)


How is this much better? I still don’t have a clue what the function does, much less any idea if it is working correctly without a unit test. ;)

At first I was wondering what your point was, but I see it now, and agree completely.

For me, in a scripting language, proper naming of variables/functions is of much higher importance than the static typing of things. i.e.:

function CalculateValue(scaleValue, index);


I don’t really care what the heck the type is - I can pretty much assume what it would be anyhow (a number followed by some sort of key value - the domain’ll dictate what that may be). I suppose you could complain that you’re never certain if there is a return value or not, but documentation should *always* be present for any public API, in my opinion – regardless of typing, otherwise you lose out on so much *other* valuable information (units, ownership, requisites, etc).

Don’t get me wrong - there’s a reason why I code the majority of my stuff in C++, and strong/static typing is a very helpful reason for that. Although, one of my larger projects is almost completely written in Lua, and I have yet to complain about the typing in that project.

Every language feature has it’s drawbacks, and some are just more suitable to some people’s way of thinking than others, I s’pose.

0
101 Feb 01, 2007 at 06:19

@monjardin

char *foo (int bar, double baz)


How is this much better? I still don’t have a clue what the function does, much less any idea if it is working correctly without a unit test. ;)

I know it wouldn’t like me very much if a send it a string, I know it does “foo” whatever that is… and why would you give me a incorrectly working function? Don’t you like me?

What I’m pointing out is: if the function works great, if it doesn’t then fix it!
Static typing gives me a understanding of what a function wants, which I prefer with or without comments.
@eddie

Every language feature has it’s drawbacks, and some are just more suitable to some people’s way of thinking than others, I s’pose.

I love language features that go “Now its a string. Now its float. Now its a string again, no wait still a float… I think… anyways nice keyboard you got there”.

0
101 Feb 01, 2007 at 06:34

@nopcoder

I love languages that go “Now its a string. Now its float. Now its a string again, no wait still a float… I think… anyways nice keyboard you got there”.

What you illustrate is a problem with the programmer, not the language. Languages aren’t bipolar, no such guarantee is given to the programmers who write in them, however. ;)

I can do the same thing you mention in C++ with a couple of C style casts, and it would be no less ugly. I concede the point that the compiler gives you a warning much sooner that you’re doing something stupid – but in practice I’ve found that to be more of a placebo than an actual “thank-God-I’ve-got-strict-typing!”.

Sorry if I seem a little stuck on this topic. I just remember a time when I started work at a web company, and I *loathed* JavaScript. I slowly grew to realize that it was not JavaScript I had taken issue with (it’s not the first on my list of languages to work with, granted), but rather the companies implementation and lack of understanding of the language. The schizophrenia of typing you depict is precisely what happened (among other stupidity), because programmers thought reusing variables was a ‘good’ thing and it led to all type (pun) of havoc (what’s worse: their C++ code server-side was an even more tangled mess of ignorance).

Long story short: a new junior developer started and cited that “strict typing was the cure to all ills”, and I debated endlessly with him, until even he conceded: while strict typing isn’t a ‘bad’ thing - the problem here was discipline and understanding of the code, rather than assuming a language feature will make you a better coder.

Anyhow, I realize my points probably won’t sway you either way, and I imagine that’s because I’m rather neutral on the whole issue – have your strict typing in everything if you want; I see it’s merits. I just don’t think it should be super high on a list of priorities, particularly for a scripting language. After all, look what great applications have been built in Lua, Python, JavaScript and the like.

0
165 Feb 01, 2007 at 07:23

@monjardin

EDIT: Just to make a point… :devil:

char *foo (int bar, double baz)


How is this much better? I still don’t have a clue what the function does, much less any idea if it is working correctly without a unit test. ;)

Granted, you still proper documentation and tests in any case. Still, including types in the function declaration makes it much easier to extract information about the function’s behavior than reading comments, IMHO. Sometimes you already know what a function does and just need a brief reminder of what the arguments are.

It doesn’t really matter so much if we’re talking about strings vs numbers or whatever, but it matters a lot if we’re talking about ADTs. For instance, I’ve worked on some web app projects in PHP where functions were passing around big datastructures that had to be in a particular format (e.g. an associative array containing some particular keys whose values were other associative arrays, etc.) - it’s just easier to work with if you can define a class and declare the parameter to be an object of the class, rather than having to explain the whole structure in your comments all the time.

Moreover, the error messages generated by a static type system are IMHO much more informative than in a dynamic type system. If I mess up and pass the wrong thing to a function, I want to see “function foo: expected parameter of type bar, got baz” rather than “in function foo: bop does not have method gazonk” and then have to trace back to find what went wrong.

I’m not intending to bash Lua or Javascript or anything as I’ve also used them successfully (in small applications); I just think static typing is more convenient and safer to use, especially in larger projects. After all, why rely solely on your programmers to adhere to a certain discipline, when you can get the compiler to enforce that discipline automatically? ;)

0
101 Feb 01, 2007 at 12:35

I personally preffer a weak typed language with strong typed capabilities just because of flexibility. But why the hell should anyone bother by using weak typed only language or even worse a typeless language when you can have strong typeness with all its benefits? (as Reedbeta observed)

Don’t get me wrong. I don’t want to persuade anyone here. I’ve just denoted that strong typeness can help you writing more robust high-quality software. That holds for scripting too.

cu,
chris

0
101 Feb 05, 2007 at 23:55

I’ve chosen to go with Squirrel (its not strongly typed, I know).
Thanks for all your input, I appreciate it.

0
102 Feb 06, 2007 at 00:30

That sounds like a good choice. I’ve heard Squirrel called Lua++ in the past and I’ve been meaning to play with it. Please let us know how it works for you!

0
101 Feb 15, 2007 at 08:57

I can give you UndeadScript, my scripting engine. It’s syntax looks a lot like a mix of Java and JavaScript. Here is an example of a source code file and from here you can download a test host application.

Note that the above files are a bit older and have a few bugs/missing featurs (f.e. there is no “for” there). However these are fixed in my current code.

I will release the library to the public once i finish it’s documentation and make my SlashDOC source code documentation tool to understand UndeadScript. Beyond docs, UndeadScript is to a usable state (actually, i used a premature version of it in my game Nikwi - but that’s a very premature version, it doesn’t even have functions :-)).

The language features strong typing, classes (with inheritance), garbage collection and an “interface description language” (USI - UndeadScript Interface) which you can use to ‘export’ functions and classes (and/or define new) from the host program.

Note that i’m not asking anyone to use UndeadScript! I made it to be used mostly be me and i’m giving it for free to anyone who may want it, but i’m not going to get into big endless discussions about “why UndeadScript is better than 3902323.77777777777777777777 other available scripting engines”. Ok?

Thank you. Now if you want it, contact me at badsector@slashstone.com. I visit my email more often than this forum :-).

0
101 Feb 15, 2007 at 10:43

Note that i’m not asking anyone to use UndeadScript! I made it to be used mostly be me and i’m giving it for free to anyone who may want it, but i’m not going to get into big endless discussions about “why UndeadScript is better than 3902323.77777777777777777777 other available scripting engines”. Ok?

If you don’t want that discussion, don’t plug your scripting language in a thread about scripting languages.

So, how *does* UndeadScript compare to other similar scripting languages? :)

0
101 Feb 15, 2007 at 11:32

Well i said about a “big endless discussion” :-).

The problem is that i don’t actually know other languages, so i can’t really answer on that one. From those i know, UndeadScript is very different from a syntax point of view since it’s mostly Java/JavaScript-like. It’s closer to AngelScript than anything else (…i know).

0
101 Feb 15, 2007 at 11:36

Ok so you made your engine more for fun than for lack of better alternatives? (which is a perfectly good reason of course, but I’m just curious)

0
101 Feb 15, 2007 at 11:45

Well, my method was simply to look how LUA and Python looks*, dislike what i saw, thought that i can do it better and end with UndeadScript :-).

Of course even if there was a better solution since i prefer to solve my problems with my own stuff, it’s possible that i would write UndeadScript anyway :-).

*=that means that i googled for LUA and saw some code snippets and later did some python development to make a 3d object exported for Blender3D.