Embedding Python/LUA

Started by
27 comments, last by John Schultz 18 years ago
Nick Gravelyn,

Just checked, I have that same problem. luaxlib.h was called lauxlib.h. Are their any libraries I need to include, or are the headers all that i need?

John,

I did have a copy of VC++ Express 2005 (still got it on a CD somewhere), but I found it very... clunky. Also, getting SDL to work was impossible, so I changed to Code::Blocks, and havent had any problems (till this). Unfortunatly, I have since uninstalled VC++, but may have to install it again, just to test if SqPlus will work with it. If is does, I'll have to find if it's easier to get SqPlus to work with Code::Blocks, or SDL with VC++. Also, how would I use these Makefiles with Code::Blocks (or dev-cpps compiler, I think it's gcc)??

Thanks for all your help.
Advertisement
Quote:Original post by Silvo
I did have a copy of VC++ Express 2005 (still got it on a CD somewhere), but I found it very... clunky. Also, getting SDL to work was impossible, so I changed to Code::Blocks, and havent had any problems (till this). Unfortunatly, I have since uninstalled VC++, but may have to install it again, just to test if SqPlus will work with it. If is does, I'll have to find if it's easier to get SqPlus to work with Code::Blocks, or SDL with VC++. Also, how would I use these Makefiles with Code::Blocks (or dev-cpps compiler, I think it's gcc)??


Silvo, do you know how to create a project from scratch using Code::Blocks? If so, you can create a new project, then add the files in each directory for Squirrel/SqPlus. You can figure out which files are needed by looking at the Makefiles in a text editor (you also need to determine which Makefiles are creating libraries, and which are creating executables). When you see *.cpp in a makefile, that means all the .cpp files in that directory, etc. You can find the docs for GNUMake here. While GNUMake is reasonably powerful, it's not well suited for beginners (though not too bad for simple projects).

It will probably take you less time to re-install VC2005 and immediately compile and run SqPlus than it will to figure out how to read Makefiles and create new projects in Code::Blocks. After re-installing VC2005, you might try Visual Assist X (VAX). VC2005+VAX rocks. After trying VC2005 (and perhaps VAX), I'd be curious to hear your analysis as to why you prefer another IDE.

BTW, if you install Cygwin, you can use the Makefiles and the gcc compiler from the command line (as noted in a previous post. Cygwin is a *nix style environment; you use ./exename etc.). Your best bet to quickly get something running is with VC2005 and SqPlus (will compile and run with no errors, no warnings, etc.). Once you are confident the scripting language is solid/what-you-want, you can figure out how to recreate the projects/makefiles with Code::Blocks, etc. However, the VC2005 compiler and debugger are the best in the business (fastest code (general case), now very standards compliant etc., compiles faster than gcc (while producing faster code (sometimes much faster, etc.)), using VAX for the first time will blow your mind (very cool/powerful: even spell checks your code; no longer waste time recompiling due to typos)).
Wow! you really like VC++. Alot. I found that it was quite clunky, oh well. I managed to get GameMonkey script to work. Just remembered about having to add .cpp files directly to the project, so that worked. Now im back to tampering with Code::Blocks, Squirrel and SqPlus, i think the reason it can't find the definitions is that they haven't been included correctly (not just #include, but I need to manually add each .cpp file that is being used). Hopefully this should make it work.

Thanks again for all your help.

EDIT: Visual Assist X looks really good. I think I'm going to have to re-install VC++ just to check it out.
I DID IT!!!!!

I have to add all these squirrel and SqPlus related files, and then not add these ones, but these ones i do... But I managed to get the minimal example to compile and run! Using Code::Blocks!!!

I'm happy!

Thanks for all the help, now I've gotta learn how to use it. Another adventure...
Quote:Original post by Silvo
I DID IT!!!!!

I have to add all these squirrel and SqPlus related files, and then not add these ones, but these ones i do... But I managed to get the minimal example to compile and run! Using Code::Blocks!!!


Cool!

Re VC++ (IDEs): VC6 was fast and clean, VC7.1 was a little slower, but more features, VC8 is even slower (perhaps that's what you mean by clunkier), but provides a better overall interface (who knows, maybe they'll speed/clean it up by version 8.1+). As for generated code, the new profile-guided optimization is pretty cool (VS2005 Pro; not sure if comes with Standard or Express).

Re VAX: It's an amazing product. Alt-O to switch between .h/.cpp, open a file in the workspace with just a few letters of the file name, find any symbol by typing a few letters, spell/validation of all variables/functions (no more typos before compile), auto-complete variables, functions, members (way less typing), faster key repeat (download the demo for more info). It's the best development enhancement tool I've seen in a long time. For really large projects, IncrediBuild is also very useful (multiple parallel builds on many machines in your office (can get expensive, but for large commercial projects, definitely worth it)). These add-in products only work with VC. Additionally, after you reinstall VS2005, compare build times when rebuilding your entire project (compared to an IDE using a gcc compiler); also compare runtime speed (optimized builds).

Now that you have GameMonkey and Squirrel/SqPlus working, you might want to also try out Lua, Python, and AngelScript. Perhaps post what you like/dislike about each language/binding system.
Thanks again for all your help. I think I will do some compile/run time tests for gcc and VC++. I just dont like to IDE, it seems too... packed. There are so many features, but everything is not as good as it could be (quantity over quality in this case). Its a little buggy too (that Intellisense thing, shudder).

Ive gotten GameMonkey to work with Code::Blocks, and can open a file and execute the script in it, but I cant find any information on how to do that with SqPlus. Ive downloaded AngelScript, LUA and Python, but have yet to get any of them to work.
Quote:Original post by Silvo
Thanks again for all your help. I think I will do some compile/run time tests for gcc and VC++. I just dont like to IDE, it seems too... packed. There are so many features, but everything is not as good as it could be (quantity over quality in this case). Its a little buggy too (that Intellisense thing, shudder).

Ive gotten GameMonkey to work with Code::Blocks, and can open a file and execute the script in it, but I cant find any information on how to do that with SqPlus. Ive downloaded AngelScript, LUA and Python, but have yet to get any of them to work.


Re: Intellisense- download and install the demo for VAX- it replaces Intellisense (and it works well).

Compiling scripts- see the SquirrelVM.h header:

Replace the call from (were s is a string script, as in the examples):
SquirrelObject CompileBuffer(const SQChar *s);

To:
SquirrelObject CompileScript(const SQChar *s); // s is a filename.

Then run as before:
SquirrelObject RunScript(const SquirrelObject &o,SquirrelObject *_this = NULL);

You could also do it this way (See the Squirrel documentation for more info (you can use "low-level Squirrel" as desired with SqPlus)):
  void printSQDBGError(HSQUIRRELVM v) {    const SQChar *err;    sq_getlasterror(v);    if(SQ_SUCCEEDED(sq_getstring(v,-1,&err))) {      printf("SQDBG error : %s",err);    }else {      printf("SQDBG error",err);    } // if    sq_poptop(v);  } // printSQDBGError// ... In your init code:  HSQUIRRELVM v = SquirrelVM::GetVMPtr();  sq_pushroottable(v);  if(SQ_FAILED(sqstd_dofile(v,"MyScript.nut",SQFalse,SQTrue))) {    printSQDBGError(v);  } // if
Well, I did it, thanks to your help.

The code:

main.cpp:
#include "sqplus.h"int main(int argc, char* argv[]){	SquirrelVM::Init();	SquirrelObject myscript = SquirrelVM::CompileScript("test.nut");	SquirrelVM::RunScript(myscript);	SquirrelVM::Shutdown();}


test.nut:
print("Hello world");


Works! Unfortunately, I don't have a clue what your code does, but it's much more complex then this. I think it's some sort of error checking thing... Ill check in the squirrel documentation. Let me just say that this is the easiest script loading/executing thing I've seen, well done! But to improve, you really need some sort of documentation/tutorial/walkthrough. It wouldn't be too hard to make, just explain how to do this type of stuff. Anywho, another one bites the dust, thanks again for you help!
Quote:Original post by Silvo
Let me just say that this is the easiest script loading/executing thing I've seen, well done! But to improve, you really need some sort of documentation/tutorial/walkthrough. It wouldn't be too hard to make, just explain how to do this type of stuff. Anywho, another one bites the dust, thanks again for you help!


Thank Alberto for that simple/clean init design: it was originally from DXSquirrel, a macro-based binding system for Squirrel (rolled into SqPlus, which is template-based (see the sqplus.h header for more credits)).

So far the Squirrel/SqPlus examples and docs have been sufficient for more advanced/commercial users. I agree that more docs would be helpful (especially for students/beginners); Squirrel/SqPlus, like many free software tools, is collaborative (so far no one has contributed beginner tutorials (easy to do on the Wiki)).

As you progress with scripting, you'll find that ease of binding/interacting-with-Cpp and debugging script code (with a good script debugger) are very important (for anything other than really small scripts). For a commercial application, it's also important to be able to (reasonbly well) understand the script-engine source code, and to be able to quickly modify it when new functionality is needed (almost always the case for a commercial production).

This topic is closed to new replies.

Advertisement