Jump to content

  • Log In with Google      Sign In   
  • Create Account


Scripting Languages


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
22 replies to this topic

#1 cnirrad   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 March 2002 - 10:16 AM

I would like to use a scripting language from C++, but the only things I''ve found are about making your own languages from scratch. Is there anyone out there not trying to re-invent the wheel and has some experience with using some existing language? I would like to know what language can be used from C++ easily, and where I can find some info about it. Thanks.

Sponsor:

#2 Null and Void   Moderators   -  Reputation: 1087

Like
Likes
Like

Posted 05 March 2002 - 10:30 AM

While there are many choices, I personally like Lua. It''s decently powerful, and is actually aimed at being used through C/C++.



#3 cnirrad   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 March 2002 - 10:39 AM

I have actually tried using Lua, both through ClanLib, and straight c/c++, but could not get it to work. It gave me about 16 errors, all of which were in the headers provided by Lua.

In fact, here are the errors straight from MSVC:

--------------------Configuration: luaTest - Win32 Debug--------------------
Compiling...
test.cpp
c:\program files\microsoft visual studio\vc98\include\lua++.h(60) : error C2146: syntax error : missing '';'' before identifier ''d_lo''
c:\program files\microsoft visual studio\vc98\include\lua++.h(60) : error C2501: ''lua_Object'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\lua++.h(60) : error C2501: ''d_lo'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\lua++.h(125) : warning C4003: not enough actual parameters for macro ''lua_pushcfunction''
c:\program files\microsoft visual studio\vc98\include\lua++.h(189) : error C2146: syntax error : missing '';'' before identifier ''d_table''
c:\program files\microsoft visual studio\vc98\include\lua++.h(189) : error C2501: ''lua_Object'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\lua++.h(189) : error C2501: ''d_table'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\lua++.h(192) : error C2629: unexpected ''class LuaObject (''
c:\program files\microsoft visual studio\vc98\include\lua++.h(192) : error C2334: unexpected token(s) preceding '':''; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\lua++.h(200) : error C2629: unexpected ''class LuaObject (''
c:\program files\microsoft visual studio\vc98\include\lua++.h(200) : error C2334: unexpected token(s) preceding '':''; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\lua++.h(247) : error C2146: syntax error : missing '';'' before identifier ''getobject''
c:\program files\microsoft visual studio\vc98\include\lua++.h(247) : error C2433: ''lua_Object'' : ''virtual'' not permitted on data declarations
c:\program files\microsoft visual studio\vc98\include\lua++.h(247) : error C2501: ''lua_Object'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\lua++.h(260) : warning C4183: ''getobject'': member function definition looks like a ctor, but name does not match enclosing class
c:\program files\microsoft visual studio\vc98\include\lua++.h(284) : warning C4003: not enough actual parameters for macro ''lua_isnil''
c:\program files\microsoft visual studio\vc98\include\lua++.h(305) : warning C4003: not enough actual parameters for macro ''lua_isfunction''
c:\program files\microsoft visual studio\vc98\include\lua++.h(312) : warning C4003: not enough actual parameters for macro ''lua_isuserdata''
c:\program files\microsoft visual studio\vc98\include\lua++.h(319) : warning C4003: not enough actual parameters for macro ''lua_istable''
c:\program files\microsoft visual studio\vc98\include\lua++.h(543) : warning C4003: not enough actual parameters for macro ''lua_register''
c:\program files\microsoft visual studio\vc98\include\lua++.h(543) : warning C4003: not enough actual parameters for macro ''lua_pushcfunction''
c:\program files\microsoft visual studio\vc98\include\lua++.h(547) : error C2061: syntax error : identifier ''lua_Object''
c:\my documents\luatest\test.cpp(23) : error C2440: ''type cast'' : cannot convert from '''' to ''class LuaValue''
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\my documents\luatest\test.cpp(23) : error C2228: left of ''.store'' must have class/struct/union type
Error executing cl.exe.

luaTest.exe - 16 error(s), 8 warning(s)

------------------------------------------------

I probably have Lua installed wrong, since the example that this is from is straight from a working example I found on the website. Any ideas?


#4 Null and Void   Moderators   -  Reputation: 1087

Like
Likes
Like

Posted 05 March 2002 - 10:49 AM

I''ve never heard of a "lua++.h" header. I just read their reference manual to figure it out. Here''s a short example of how to parse a single script file named "test.lua":
  
#include <lua.h>


int main(void) {
lua_State *State;

State = lua_open(0);
lua_dofile(State, "test.lua");
lua_close(State);

return 0;
}

The "test.lua" file can just be empty for now. That''s meant to be a C file, not C++. If you want it to be C++, replace the include with:

#ifdef __cplusplus
extern "C" {
#endif
#include <lua.h>
#ifdef __cplusplus
}
#endif

Link whatever libraries are required and build it; Make sure it works. If it doesn''t, something is setup incorrectly.



#5 cnirrad   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 March 2002 - 11:03 AM

The example complied correctly! I don''t remember exactly where I found the lau++.h, but I got it because I thought I needed it for cpp. Anyway, it seems to be working, thanks a lot!

#6 Ziphnor   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 March 2002 - 11:26 AM

You might also want to check out:
http://www.mozilla.org/js/spidermonkey/

That way you can use java-scripting for scripting language.
It has a really good searchable API specification, though the tutorials are a little bit lacking.
Anyway, its quite easy to use.

#7 Siebharinn   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 March 2002 - 12:21 PM

I use python for all of my scripting needs. It''s pretty easy to set up, and I''m working on some macros to make it even easier.

Take care,
Bill

#8 Rickmeister   Members   -  Reputation: 182

Like
Likes
Like

Posted 06 March 2002 - 08:03 AM

Here''s a link to lua++ just incase someone is interested.. Personally I''ve been struggling for a long time to try to embed Python into my app.. Still got a long way to go before it works as it is supposed to do..

Don''t give up..

Wannabe

#9 Kwizatz   GDNet+   -  Reputation: 1188

Like
Likes
Like

Posted 06 March 2002 - 08:16 AM

Never heard of Lua, will give it a try, after giving up embeding PERL, I decided to go with TCL, get the ActiveState implementation if interested, its simple both to program and embed, but it is more suited to work with C than C++.

anyway, good luck!



#10 Dak Lozar   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 March 2002 - 02:55 PM

I had originally started using spidermonkey (java-script) and got it to compile into my test app. But became quite irritated with their implementation of classes around classes.

I finaly wound up with a nice little scripting language that you guys might want to check out; Simkin. I read about it here and then went to download it... you have to send a request and provide information regarding it''s use... but in all honesty it''s worth the trouble.

I haven''t been working with it lately but I like the way it implements scripts - you can use XML and what the author calls treenode. I personally like the treenode because the parser is built-in, the XML script needs another parser not included in the package. But if you have a class and want to expose it to the interpreter it''s really easy - much easier than spidermonkey.

Happy coding (and scripting)

Dave "Dak Lozar" Loeser

#11 DrPizza   Members   -  Reputation: 160

Like
Likes
Like

Posted 06 March 2002 - 06:00 PM

Just go for COM and ActiveX Scripting (or .NET hosting if you want to be fancy schmancy). Much easier in the long run -- if someone wants to use their preferred scripting language then they just have to install an appropriate ActiveX control.


#12 Warpstorm   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 March 2002 - 03:15 AM

I''d have to second the nomination for python. Python is very slick and well supported. You can find lots of online tutorials and actual books on it. It also comes with a very useful set of libraries.

#13 Kwizatz   GDNet+   -  Reputation: 1188

Like
Likes
Like

Posted 07 March 2002 - 04:49 AM

a Word on COM + ActiveX, its only supported in Windows, be 100% sure you want your game to run on nothing but Windows before taking that option, or well be prepared to do a lot of porting afterwards.

Checked LUA, seems great, C like syntax, object support, small and portable out of the box, no strings attached, I think thats the way to go, have to do some more checking though



#14 DaTroof   Members   -  Reputation: 162

Like
Likes
Like

Posted 07 March 2002 - 05:29 AM

quote:
Original post by Kwizatz
Never heard of Lua, will give it a try, after giving up embeding PERL, I decided to go with TCL, get the ActiveState implementation if interested, its simple both to program and embed, but it is more suited to work with C than C++.

anyway, good luck!




I'm using TCL for my game engine's embedded interpreter. It works great. I had to jump through a couple of hoops to make my command extensions (written in C) work with C++, but it was mostly painless.

If anyone's curious, TCL somewhat resembles LISP, but with a lot fewer parentheses ;-)

[EDIT] Sorry for the double post.


Edited by - DaTroof on March 7, 2002 12:30:42 PM

#15 Ziphnor   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 March 2002 - 08:45 AM

I cant speak for the other scripting languages mentioned here, but using the SpiderMonkey java-script engine is real easy, and you can compile scripts on program initilization.

It really isnt much harder than calling
JSScript* scriptPointer = JS_CompileScript(char* script, a few standard params) as soon as possible and then JS_ExecuteScript(scriptPointer,..standard params..) when the script is needed. Better than a pure interpreter anyway.

Defining native functions that are exposed to the script, is also very easy, but i dont think its possible to check very well for number of passed arguments and their type before its too late.

Also java-script is a pretty good scripting language, the syntax is simple but is reminiscient(spelling?) of Java/C/C++.

And no, im in no way affiliated with the people who made it

Edited by - ziphnor on March 7, 2002 3:56:13 PM

#16 OOProgrammer   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 March 2002 - 11:37 AM

I''m in need of a scripting language suited to a text-based rpg. Anyone who''s played around with MOO will know what kind of capabilities I want. Any recommendations? At the moment I''m looking at Python because it''s OO and (supposedly) plays nice with C++.

-----------------------------------
"It''s groin-grabbingly transcendent!" - Mr. Gamble, my teacher, speaking of his C++ AP class

#17 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 07 March 2002 - 07:17 PM

compiled script are better than interpreted since they are faster, and has a smaller size.. i personally dont like the idea of linking native functions using a table since its not practical and harder to code. i prefer compiled script (virtual assembly) so the VM function can be created just like normal assembly i.e. via interrupt. parameters are stored in stack.

''compuphase small'' is a good and fast scripting language, but not easy to implement native functions because it uses dynamic-typed variables. normal typed variable are faster and easier to code.

my recommendation for building your own ''c'' style scripting lang. is by using Gold Parser, quite efficient but not easy..

(phew.. always anonymous)

#18 Dak Lozar   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 March 2002 - 02:16 AM

quote:
Original post by Ziphnor
It really isnt much harder than calling
JSScript* scriptPointer = JS_CompileScript(char* script, a few standard params) as soon as possible and then JS_ExecuteScript(scriptPointer,..standard params..) when the script is needed. Better than a pure interpreter anyway.


Hi Ziphnor,
I started out investigating spidermonkey... I got the interpreter into my code and compiled without much fuss. But, when it came time to expose my objects I became frustrated by the manner in which they force you to wrap the java-script classes around your classes. Did I miss something or are you not exposing classes to the interpreter?

I was sold on using Spidermonkey because of the language itself and how easy it is for non-programers to pick it up and write script... so the only thing I have to solve before moving back to the monkey is how to expose my objects (or rather the API that I want the script writers to use).

Thanks,


Dave "Dak Lozar" Loeser

#19 Ziphnor   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 March 2002 - 09:45 AM

I decided to go with a handle based system.

For example(in AI script)

getNearestEnemy() returns a handle(integer) to the nearest hostile game object. The script language can then call for example setTarget(myHandle, getNearestEnemy()) etc.

You can also expose factory methods to the script, that can construct objects on the native(C/C++) side, but only recieving a handle to it.

Forgot this: Performance wise, a handle system is also pretty smart because it means there is less conversions going on between the native and script side. Sending alot of data between the 2 is expensive.

Edited by - ziphnor on March 8, 2002 4:49:27 PM

#20 McMcDonald   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2002 - 11:08 PM


Hi!

If i want to use python - do i have to open the source of my game ?

I interpret the "open source definition 1.9" in the way that i have to publish the source of my commercial projects to be able to use python.

McMc




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS