Dark
Dark

Reputation: 343

Can I use C as a scripting language for my engine?

I have a game engine right now and I'm looking for a scripting language for it. I tried Lua and find it quite good but I want to have my script to look like C or better C++ or look like unreal engine's script would be better.

Is that even possible?

Upvotes: 9

Views: 4031

Answers (6)

Necrolis
Necrolis

Reputation: 26171

TCC has a a library allowing for dynamic compilation of C code, and seeing as its pretty fast as a C compiler, its can be used to compile stuff (almost) on-the-fly, there is a really basic example here, however the TCC documentation in the header is way better in explaining stuff.

it also comes with a better example of its own showing how to expose symbols to the compiler when using libtcc, this can allow you to sandbox your scripts if you disable certain portions of the compiler (mainly the import of external libraries other than those on a safe list), which is possible as its fully opensource and not too complex and it has some basic documents on its internal structure.

Upvotes: 2

malkia
malkia

Reputation: 1387

Check AngelScript, GameMonkey, and there are many others

http://codeplea.com/game-scripting-languages

Or maybe go the hard-way and integrate the CINT C/C++ interpreter (http://root.cern.ch) with the ROOT library. The idea is that you would be interpreting all your .c/.cpp files that you are actively working on, while the rest are compiled (your choice).

For example you are the audio programmer, you would like the rest of the non-audio code to be blazingly fast, while the stuff you are actively working not so, but to have fast iteration - hot-loading, change on the fly, etc.

In addition CINT interpreter has extra dynamic language facilities - you can introspect (reflection) - allowing you to create for example serializers for packing of your game assets, or whatever you might need.

There is also UnderC, and Ch (as being mentioned) and many many others...

Upvotes: 4

user629132
user629132

Reputation:

There are number of scripting languages with more or less C like syntax. Others already mentioned ECMAScript, another option would be s-lang, which was designed as a scripting language, is easy to embed, and has a syntax that is pretty close to C.

Upvotes: 2

Joe Tyman
Joe Tyman

Reputation: 1417

Like what like @Charles said use Metalua if you want something easy to implement and have flexibility. If you want a C-like scripting language you can try ECMAScript or any of it supersets(JavaScript, JScript, ActionScript).

Upvotes: 1

Charles Stewart
Charles Stewart

Reputation: 11837

Metalua is language implementation system based on the Lua codebase that exposes various language innards such as the parser (gg/mlp), so allowing you to extend the language or completely change the syntax. Think of a cross between yacc and a Lispy metacircular interpreter.

It's not quite clear to me what you are after with look like C or better C++, but I think this sounds along the right lines and offers a nice balance between implementation ease and flexibility.

Upvotes: 2

Atmocreations
Atmocreations

Reputation: 10061

Sure you can :P You can do everything if you want to.

I currently see these three ways:

  • Either you write the code yourself to parse the C/C++-Code, which really isn't an easy task
  • You use a parser which analyzes and interprets C-Code. Ch Standard edition should do the trick as it can be included in own projects as a scripting language.
  • Another way would be to create a script which dynamically compiles the user-generated code to a shared library which is dynamically loaded by your engine. Although this wouldn't be "scripting" anymore.

Upvotes: 7

Related Questions