Scripting Languages

Started by
21 comments, last by cnirrad 22 years, 1 month ago
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.
Advertisement
While there are many choices, I personally like Lua. It''s decently powerful, and is actually aimed at being used through C/C++.

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?
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 __cplusplusextern "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.

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!
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.
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
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
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 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
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous

This topic is closed to new replies.

Advertisement