• Advertisement
Sign in to follow this  

scripting language with c++ like syntax?

This topic is 4295 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi do you know any scripting languages that use the c++ syntax? thx

Share this post


Link to post
Share on other sites
Advertisement
squirrel.

But i am having serious troubles with embedding it, if you find any good sources, let me know.

Share this post


Link to post
Share on other sites
Game Monkey is pretty heavily based on C++ syntax.

http://www.somedude.net/gamemonkey/

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Angelscript: http://www.angelcode.com/angelscript

Share this post


Link to post
Share on other sites
Quote:
Original post by Basiror
Hi do you know any scripting languages that use the c++ syntax?


If you have Visual Studio 2005 (VS8, Express version is free), you can download the Squirrel/SqPlus .zip, compile and run in about 5 minutes.

If using a gcc compiler and a Unix like environment (or cygwin on Win32), simple GNUMake files are provided.

Share this post


Link to post
Share on other sites
Thx guys I need to read up the feature sets of the individual languages before I decide for one

thx

Share this post


Link to post
Share on other sites
Yeah, Squirrel is really nice, especially Sqplus/SquirrelPlus (By John Schultz :D), I literally got it up and running within a minute of downloading it :') It's built with lua's faults in mind.

Share this post


Link to post
Share on other sites
Do you want C++-like syntax or C++-syntax? If the latter, check out CINT (http://root.cern.ch/root/Cint.html), a C++-Interpreter, which is somewhere around 90%-compliant. But beware, it's a mighty tool.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Basiror
Hi do you know any scripting languages that use the c++ syntax?


Is there any comprehensive overview of the the various most popular scripting languages (suited for embedding) and their major features available? Or maybe even some searchable database, where you could search for certain characteristics (i.e. license,ECMA-like,OO,concurrency etc.)?

Thanks

Share this post


Link to post
Share on other sites
I'd question WHY you want a C++ syntax in the first place...

You might want to ask yourself a couple of questions:

- Who's using the system? Unless it's all programmers, C++ syntax can be very painfull (i.e. artists, designers, scripters).

- What's the reason for moving stuff to script? There are some good reasons (run-time recompile, data-driven binding, etc), but by going for a very C++ like langauge, you're loosing the higher level functionality from languages like Python or Lua.

- At the same time you loose the kick-ass debugger you're used to in C++, and probably loose some of your speed as well.

You might be better off using some other option:
- Higher level language (Lua, Python, or even a functional language)
- Run-time linked DLLs; combined with dynamic loading/unloading you can get run-time recompile, while at the same time keeping the debugger and the C++ speed
- If you're running on .NET, you could consider going for C# as your scripting language; there's a sample of how to do that in the DX SDK.... might be worth doing.


Good luck,

Allan

Share this post


Link to post
Share on other sites
Quote:
Original post by __ODIN__
I'd question WHY you want a C++ syntax in the first place...


I used to use and recommend Lua; however the syntax difference between Lua and C++ provided no benefit for using Lua over C++. Once you remove the syntactic sugar for Lua and re-candy coat it for a more C++ syntax, artists/level designers won't have any more problems vs. using Lua-syntax, and C++ developers will be able to work faster. Thus, it's a net win to use a C++ style syntax.

Quote:
Original post by __ODIN__
- At the same time you loose the kick-ass debugger you're used to in C++, and probably loose some of your speed as well.


The (C++ -like syntax based) scripting language that I currently use and recommend (Squirrel) provides a high quality, syntax highlighted remote debugger (works reasonably well). It can do everything Lua can do (some parts derived from Lua), and scales better for large commercial projects (Lua may be faster for some smaller apps where memory issues aren't present).

Another big challenge is binding the scripting language to C++. I created SqPlus for Squirrel to make integation+binding simple+easy (borrowed ideas from LuaPlus and Luabind, then simplified and generalized). Luabind for Lua and boost.Python for Python are more powerful, but also far more complicated (must use boost, etc.).

I haven't used AngelScript, but from forum posts it appears to also be simple to use and supports a C++ style syntax (differs from Lua, Python, Squirrel by using typed variables).

Quote:
Original post by __ODIN__
- If you're running on .NET, you could consider going for C# as your scripting language; there's a sample of how to do that in the DX SDK.... might be worth doing.


C# rocks; for a Win32-only target, C# scripting can't be beat in terms of compile-time + run-time (only slightly slower than C++ in some cases).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I have also been looking for a C/C++-like scripting language for a small uni project and Squirrel looks interesting, however how straightforward is embedding it and how feasible is it to transfer data between the host application and the scripts? In particular, how feasible is it to access C++ classes from the script, and custom script types from C++?
Also, is it actually suited to be run in a multi-threaded environment?
Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
I have also been looking for a C/C++-like scripting language for a small uni project and Squirrel looks interesting, however how straightforward is embedding it and how feasible is it to transfer data between the host application and the scripts? In particular, how feasible is it to access C++ classes from the script, and custom script types from C++?
Also, is it actually suited to be run in a multi-threaded environment?
Thanks


Binding a class, functions, and variables is simple (_T() is for UNICODE compatibility):

SQClassDef<MyClass>(_T("MyClass")).
func(&MyClass::process,_T("process")).
var(&MyClass::classVal,_T("classVal"));




Example from minimalSqPlus.cpp. Defines a C++ class, binds to the script system, calls script, which calls C++ function and accesses variable (formating blown out by forum software; see original source):

class MyClass {
public:
int classVal;
// See examples in testSqPlus2.cpp for passing arguments to the constructor (including variable arguments).
MyClass() : classVal(123) {}
bool process(int iVal,const SQChar * sVal) {
scprintf(_T("classVal: %d, iVal: %d, sVal %s\n"),classVal,iVal,sVal);
classVal += iVal;
return iVal > 1;
} // process
};

int main(int argc,char * argv[]) {
SquirrelVM::Init();

// See examples in testSqPlus2.cpp for script read-only vars, constants,
// enums, static/global functions, variable arguments, constructor arguments,
// passing/returning classes/structs by value or by address, etc.
SQClassDef<MyClass>(_T("MyClass")).
func(&MyClass::process,_T("process")).
var(&MyClass::classVal,_T("classVal"));

SquirrelObject helloSqPlus = SquirrelVM::CompileBuffer(_T(" local myClass = MyClass(); \n local rVal = myClass.process(1,\"MyClass1\"); \n print(\"Returned: \"+(rVal ? \"true\" : \"false\")); \n rVal = myClass.process(2,\"MyClass2\"); \n print(\"Returned: \"+(rVal ? \"true\" : \"false\")); \n print(\"classVal: \"+myClass.classVal); \n "));

try {
SquirrelVM::RunScript(helloSqPlus);
} catch (SquirrelError & e) {
scprintf(_T("Error: %s, %s\n"),e.desc,_T("Squirrel::helloSqPlus"));
} // catch

SquirrelVM::Shutdown();
return 0;

} // main




OS multithreading is not currently supported [would be complicated to implement/slow down the interpreter] (though you can use script 'generators/coroutines' as with Lua).

Using multiple VM's (virtual machines), it should be possible to run multiple Squirrel VM's in multiple threads (any thread intercommunication would require some form of mutex).

Share this post


Link to post
Share on other sites
Quote:
Original post by John Schultz
I used to use and recommend Lua; however the syntax difference between Lua and C++ provided no benefit for using Lua over C++. Once you remove the syntactic sugar for Lua and re-candy coat it for a more C++ syntax, artists/level designers won't have any more problems vs. using Lua-syntax, and C++ developers will be able to work faster. Thus, it's a net win to use a C++ style syntax.


While I personally use LUA (mainly for UI integration and some data-definition), I don't really consider myself an evangelist. I'm more pointing out (from having used different scripting languages, and having seen fellow professionals and some of my students alike using scripting languages), some common pitfalls.

1. The programmer, knowing C++, wants to use a scripting language similar to it.
2. However, the scripting language is often not targetting him (very often, he could do it faster in ACTUAL C++ instead)
3. The designer, who struggles with for loops, never mind multiple inheritance, wants something simple; basically some if statements and some "go here and do that" type logic.
4. Closely mirroring C++ classes (as through straight reflection) generally leaves you open to the kind of issues scripting should hide from you (underlying class hierarchy, implementation details, crashes on invalid pointers, etc).
5. This is a personal opinion, of course, but I see Scripting as a tool that should aim to provide a safe sandbox environment at a 'higher level' (so "go to and do", rather than "pathfinding and rendering").

Having said that; each user picks the best tradeoff for himself.. If you're a programmer working alone on a project, you might not need a scripting language at all. If you're working in a programmer heavy environment, something like Squirrel might be best for you (allowing C++ programmers to be immediatly productive). If you're working as a fascilitator for artist/designers to interact with your engine, you may go for something with a more simplified syntax, and more forgiving parser.

There's no wrong answer, just different advantages.

Allan

Share this post


Link to post
Share on other sites
Quote:
Original post by __ODIN__
While I personally use LUA (mainly for UI integration and some data-definition), I don't really consider myself an evangelist. I'm more pointing out (from having used different scripting languages, and having seen fellow professionals and some of my students alike using scripting languages), some common pitfalls.

1. The programmer, knowing C++, wants to use a scripting language similar to it.
2. However, the scripting language is often not targetting him (very often, he could do it faster in ACTUAL C++ instead)


True. I have prototyped code in script, then moved it over to C++ when I found such elements were faster to develop/debug in C++.

Quote:
Original post by __ODIN__
3. The designer, who struggles with for loops, never mind multiple inheritance, wants something simple; basically some if statements and some "go here and do that" type logic.


This can be implemented in Lua, Python, Squirrel, etc., by binding the script to C++ appropriately.

Quote:
Original post by __ODIN__
4. Closely mirroring C++ classes (as through straight reflection) generally leaves you open to the kind of issues scripting should hide from you (underlying class hierarchy, implementation details, crashes on invalid pointers, etc).
5. This is a personal opinion, of course, but I see Scripting as a tool that should aim to provide a safe sandbox environment at a 'higher level' (so "go to and do", rather than "pathfinding and rendering").


True, although it's important that it should be possible to implement any construct you see fit (such as full reflection if the project may benefit, or a very tightly controlled sand box-like environment). You haven't implemented your real-time raytracer or visual protein folding-program in Lua yet? [wink]

Quote:
Original post by __ODIN__
Having said that; each user picks the best tradeoff for himself.. If you're a programmer working alone on a project, you might not need a scripting language at all. If you're working in a programmer heavy environment, something like Squirrel might be best for you (allowing C++ programmers to be immediatly productive). If you're working as a fascilitator for artist/designers to interact with your engine, you may go for something with a more simplified syntax, and more forgiving parser.


Again, I agree, however with respect to Lua and Squirrel as far as the script-writer is concerned, the biggest difference is syntax (they are both table-based typeless scripting languages; Squirrel directly supports classes (single inheritance), while Lua must emulate them). From experience with using Lua with LuaPlus and Squirrel with SqPlus, the later is far easier to integrate with C++, easier to write script code, and easier to debug with a visual debugger.

Since good artists/level designers have had no problem ([wink]) learning MAXScript (for 3DSMax) and MEL (for Maya), they will have no problem using Lua, Python, Squirrel, AngelScript, GameMonkey, javascript, Java, or C# (the interface-to-game-engine environment can be sandboxed/simplified as needed).

This brings us back to chosing scripting languages that are easy to integrate with C++, ease of writing script code, and ease of debugging with a good debugger (clearly C# wins here (amazing IDE/debugger, almost as fast as C++, becoming more portable (Mono, dotGNU)), however I would rank Squirrel second due to its ease of integration (easier than C#, also portable) and simpler language). Interestingly, I was surprised to see that VS2005 syntax highlights Squirrel source, and Visual Assist X further applies syntax highlighting (Squirrel source files defined as script file type). Not as nice as C# with full code completion/suggestion-lists, but cool nonetheless.

Share this post


Link to post
Share on other sites
Quote:
Original post by John Schultz
Interestingly, I was surprised to see that VS2005 syntax highlights Squirrel source, and Visual Assist X further applies syntax highlighting (Squirrel source files defined as script file type). Not as nice as C# with full code completion/suggestion-lists, but cool nonetheless.


Interesting, I tried getting syntax highlighting working with Visual Studio 2005 Express (havn't tried since I got Standard though), and it would only highlite the c++ keywords, not squirrel keywords (ie, things like do, for, etc highlited, but things like function, were not). I tried implementing some custom highlighting rules, but they ended up highlighting c++ files with squirrel highliting rules :/ So, I dropped that, and use a simple Editor (Programmers Notebook2), which I created a syntax highlighting rule for, and use PN2 to load up a project full of Nut's, and have a quick launch to save open files, and launch my test App :) But, if 2005 Standard can highlite Squirrel, I would much prefer that. I have not yet tried the Exclipse debugger integration, but I will have to as sometimes debugging squirrel code can be hard.

Anyway, back on point, I also recommend Squirrel, easy to use, easy to bind, and pretty slick syntax once you get used to it :)

Share this post


Link to post
Share on other sites
Quote:
Original post by pjcast
Quote:
Original post by John Schultz
Interestingly, I was surprised to see that VS2005 syntax highlights Squirrel source, and Visual Assist X further applies syntax highlighting (Squirrel source files defined as script file type). Not as nice as C# with full code completion/suggestion-lists, but cool nonetheless.


Interesting, I tried getting syntax highlighting working with Visual Studio 2005 Express (havn't tried since I got Standard though), and it would only highlite the c++ keywords, not squirrel keywords (ie, things like do, for, etc highlited, but things like function, were not). I tried implementing some custom highlighting rules, but they ended up highlighting c++ files with squirrel highliting rules :/ So, I dropped that, and use a simple Editor (Programmers Notebook2), which I created a syntax highlighting rule for, and use PN2 to load up a project full of Nut's, and have a quick launch to save open files, and launch my test App :) But, if 2005 Standard can highlite Squirrel, I would much prefer that. I have not yet tried the Exclipse debugger integration, but I will have to as sometimes debugging squirrel code can be hard.

Anyway, back on point, I also recommend Squirrel, easy to use, easy to bind, and pretty slick syntax once you get used to it :)


For basic debugging, sprinkling print() works fine, though the visual debugger is nice for more complex issues (and is faster than adding all the print() statements).

The syntax highlighting isn't perfect (VS2005Pro), but it looks nice (some of it is due to VAX):


Not sure if setting .nut as Script does anything, though saving the .nut files as .cpp got some form of IntelliSense/VAX to pop up.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This looks pretty good, but I am not using Win32-is there a vim syntax hightlighting file for squirrel available, too?
Thanks

Share this post


Link to post
Share on other sites
I've been using spidermonkey( mozilla's javascript engine ) for a few of my projects and one at work. I find its pretty easy to use and javascript can be object oriented. I'm not sure if that's close enough to C++ for you but it fufills the problem of C++ being to "hard" for some scripters.

Cheers
Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
This looks pretty good, but I am not using Win32-is there a vim syntax hightlighting file for squirrel available, too?
Thanks


There was a post on the Squirrel forum about someone starting to implement VIM highlighting. Perhaps make a post there asking about VIM support.

Some example HL files (should be able to convert to other systems fairly quickly: if converted, please post your conversions for others to use):

Colorer HRC:

<?xml version="1.0" encoding="windows-1251"?>
<!DOCTYPE hrc PUBLIC "-//Cail Lomecb//DTD Colorer HRC take5//EN"
"http://colorer.sf.net/2003/hrc.dtd">
<!--
Syntax highlighting for squirrel scripts
For installation put it into subdirectory hrc/auto of colorer (version take5)
-->
<hrc version="take5" xmlns="http://colorer.sf.net/2003/hrc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://colorer.sf.net/2003/hrc http://colorer.sf.net/2003/hrc.xsd">

<prototype name="squirrel" group="scripts" description="squirrel">
<filename>/\.nut$/i</filename>
</prototype>

<type name="squirrel">
<import type="def"/>
<import type="c"/>

<scheme name="squirrel">
<inherit scheme="def:PairedBrackets">
<virtual scheme="def:PairedBrackets" subst-scheme="squirrel"/>
</inherit>
<block start="/\/\//" end="/$/" scheme="def:Comment" region="Comment"/>
<block start="/\/\*/" end="/\*\//" scheme="def:Comment" region="Comment"
region00="def:PairStart" region10="def:PairEnd"/>
<inherit scheme="def:CHexNumber"/>
<inherit scheme="def:FloatNumber"/>
<inherit scheme="def:DecNumber"/>
<inherit scheme="c:String"/>
<inherit scheme="c:Character"/>
<keywords region="def:Error">
<symb name="["/><symb name="]"/>
<symb name="{"/><symb name="}"/>
<symb name="("/><symb name=")"/>
<symb name="*/"/>
</keywords>
<keywords region="def:Symbol">
<symb name=";" region="def:SymbolStrong"/>
<symb name="="/><symb name="+"/><symb name="-"/>
<symb name="/"/><symb name="*"/>
<symb name="&"/><symb name="^"/>
<symb name="|"/><symb name=":"/>
<symb name=","/><symb name="."/>
<symb name="!"/><symb name="~"/>
<symb name="<"/><symb name=">"/>
<symb name="%"/><symb name="?"/>
</keywords>
<keywords region="def:Keyword">
<word name="break"/>
<word name="case"/>
<word name="catch"/>
<word name="class"/>
<word name="clone"/>
<word name="continue"/>
<word name="default"/>
<word name="delegate"/>
<word name="delete"/>
<word name="else"/>
<word name="extends"/>
<word name="for"/>
<word name="foreach"/>
<word name="function"/>
<word name="if"/>
<word name="in"/>
<word name="local"/>
<word name="null"/>
<word name="resume"/>
<word name="return"/>
<word name="switch"/>
<word name="this"/>
<word name="throw"/>
<word name="try"/>
<word name="typeof"/>
<word name="while"/>
<word name="parent"/>
<word name="yield"/>
<word name="constructor"/>
<word name="vargc"/>
<word name="vargv"/>
<word name="instanceof"/>
<word name="true"/>
<word name="false"/>
</keywords>
</scheme>
</type>
</hrc>





UltraEdit:

/L20"Squirrel" Line Comment = // Block Comment On = /* Block Comment Off = */ File Extensions = NUT
/Delimiters = ~!@%^&*()-+=|\/{}[]:;"'<> , .?
/Function String = "%[ ^t]++function^(*(*)^)"
/Function String 1 = "%[ ^t]++^(*^)=[ ^t]++function*(*)"
/Indent Strings = "{"
/Unindent Strings = "}"
/Open Fold Strings = "{"
/Close Fold Strings = "}"
/C1"Keywords"
break
case catch class clone continue
default delegate delete
else extends
false for function
if in instanceof
local
null
resume return
switch
this throw true try typeof
while
parent
vargc vargv
yield
/C2"Objects"
/C3"Functions"
array assert
collectgarbage compilestring
enabledebuginfo
format
getroottable getstackinfos
newthread
print
setdebughook seterrorhandler
type
/C4"Methods and Properties"
_add _call _cloned _cmp _delslot _div _get _modulo _mul _newslot _nexti _set _sub _typeof _unm
constructor
/C5"Operators"
!

?
[
]
^
|
~
/C5"Separators"
(
)
,
;
{
}





More highlighting info here.

Share this post


Link to post
Share on other sites

Make a reg file and Merge it in the registry.
you can try this for vc7

REGEDIT4
[HKEY_CURRENT_USER\Software\Microsoft\Devstudio\6.0\Build System\Components\Platforms\Win32 (x86)\Tools\32-bit C/C++ Compiler for 80x86]
"Input_Spec"="*.c;*.cpp;*.cxx;*.nut"
[HKEY_CURRENT_USER\Software\Microsoft\Devstudio\6.0\Text Editor\Tabs/Language Settings\C/C++]
"FileExtensions"="cpp;cxx;c;h;hxx;hpp;inl;tlh;tli;rc;rc2;nut"

for vc6
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Devstudio\6.0\Build System\Components\Platforms\Win32 (x86)\Tools\32-bit C/C++ Compiler for 80x86]
"Input_Spec"="*.c;*.cpp;*.cxx;*.nut"
[HKEY_CURRENT_USER\Software\Microsoft\Devstudio\6.0\Text Editor\Tabs/Language Settings\C/C++]
"FileExtensions"="cpp;cxx;c;h;hxx;hpp;inl;tlh;tli;rc;rc2;cc;nut"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Basiror
Hi do you know any scripting languages that use the c++ syntax?

http://root.cern.ch/root/Cint.html


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
These are just a list of how I feel I moved from certain languages to the current ones I embed (all four co-exist nicely) in whatever applications I do.

C -> ICI
Perl -> Ruby
mIRC -> Tcl
javascript -> Squirrel

Share this post


Link to post
Share on other sites
Hi,
Sorry if I feed this thread a bit late, but I just wanted to mention there was an article you might want to look at in Game Programming Gems 6.

-> 4.1 - Scripting Language survey. (page 323)
Covered scripts: Python, Lua, GameMonkey, AngelScript.
Focusing on: Language features and ease of coding, integration with c/c++, performance, additionnal features ( tools like debugging, profiling, logging...)

Of course buying this book just for this article is overkill :) but maybe you can borrow it or somethin.

Anyway, I hope I helped.

Janta

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement