🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Help compiling code

Started by
10 comments, last by WitchLord 19 years, 9 months ago
Argg, I'm already having trouble. I read on the overview how to write a program that compiles anglescript code, and I wrote a program. The problem is, it crashes when it runs (no compiler or linker errors)!

#include <angelscript.h>

int main(int argc, char *argv[])
{
  asIScriptEngine *engine;
  
  // Load the script
  const char *script = "script.ang";

  // Compile the script
  engine->AddScriptSection("module", "section", script, strlen(script), 0);
  engine->Build("module", 0);
  
  return 0;
}  

That's my C++ code

float global_var = 0;

void DoSomething()
{
  ++global_var;

  if( global_var > 10 )
    global_var = 0;
}

That's the angel script code. I used the library that I created with the Dev-C++ project file. I think it may be a problem with the library I made, but I'm not sure. On a similar note, PLEASE make a downloadable static library!
Advertisement
OK, first of all, engine is just pointing to a random bit of memory, you need to call asCreateScriptEngine. You should then release this at the end of your program.
Secondly, AddScriptSection doesn't load the file for you. You need to load the file and get all of it's data and place it in a char array.
So, you should have somehting similar to this:
void RunScript(){	asIScriptEngine * engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);	const char * script = LoadScript("c:\\scriptfil.as"); //Get all the information from the file	engine->AddScriptSection(0, "section", script, strlen(script));	engine->Build(0, NULL);	ret = ExecuteScript();	asIScriptContext * ctx;	engine->CreateContext(&ctx);		//Prepare context	ctx->Execute();	ctx->Release();	engine->Release();}


You will need to do error checking and I've probably missed a whole lot of stuff out, but you should get a feel for it.

The best examples (and the way I'm learning about angel script) are found in the test framework, you should download it and go through the code.

Hope this is enough to get you started.

EDIT: Changed some of the source code (forgot to add script section!)
Thanks for your help and test framework recommendation! Still, I find it very difficult sorting through all that code. Is there a tutorial anywhere? The dox don't include any examples.
I guess I won't be using angle script then.

../../../Documents and Settings/Grant Williams/Desktop/angelscript/lib/libangelscript.a(as_scriptengine.o)(.text+0x395):as_scriptengine.cpp: undefined reference to `asCModule::~asCModule()'
../../../Documents and Settings/Grant Williams/Desktop/angelscript/lib/libangelscript.a(as_scriptengine.o)(.text+0x427):as_scriptengine.cpp: undefined reference to `asCString::~asCString()'
../../../Documents and Settings/Grant Williams/Desktop/angelscript/lib/libangelscript.a(as_scriptengine.o)(.text+0x5e2):as_scriptengine.cpp: undefined reference to `asCString::~asCString()'
../../../Documents and Settings/Grant Williams/Desktop/angelscript/lib/libangelscript.a(as_scriptengine.o)(.text+0x5f9):as_scriptengine.cpp: undefined reference to `asCString::~asCString()'
etc. (removed the rest of the 300 errors because it was slowing the page loads)

[/source]
That's what happens when I use that engine create function. It's probably a static library problem. Sigh, back to python.

[Edited by - Drakkcon on September 8, 2004 7:29:29 PM]
Please, don't be so hasty to give up on AngelScript. The linker errors you are getting is because the Dev-C++ project file you're using isn't up to date. You'll need to include the files as_string.cpp, as_string_util.cpp, and as_module.cpp for compilation. If you do add the files, could you send me the new project file so that I can update the site?

I'm sorry that I don't have a complete tutorial that tells how to get things working. The overview article, and the test_framework.cpp are the closest thing to a tutorial that I have at the moment. Each test case in the test_framework are working examples on using the library.

If you just have a little patience I will do my best to help you getting everything up and running.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I realize that he is already past this problem, but how about making a simple function (or class) to automatically load in a script file into an array. Beginners usually don't like to sit there and code this by hand, so I figure it will be helpful. I took 5 minutes and came up with a simple one here. You can do whatever you want with it.

http://www.xl3d.com/angelscript/asLoadFile.h

All they would have to do is include that file above, and the above example would turn into :

asLoadFile file("test.cpp");engine->AddScriptSection("module", "section", file, file.Size(), 0); /* Note you can test file to see if its NULL. If so, then the file wasn't loaded or empty. */
There is a file loader code in the testframework testexecutestring.cpp or something , and if simply need to get the feeling of this library or see how it behaves under different conditions, its simply to paste that code in your project or modify it there.

Sorry to sound a little rude, but a you probably need to get a few tutorials or books on c++ programming first, how you will use c++ and bind c++ code on scripts when you dont know what a pointer is ?
Completely understood, but for people just starting off who want to play with scripts, it would be nice to not have to go through and look for it. I wasn't aware this was already in there. Its a pretty simple task like I said, but it should just be made more visible for beginners.
Thanks for the recommendation. I'll update the overview article with a quick implementation for loading a script file.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thank you very much for all of your help people. It's also very nice to see how involved WitchLord is with his scripting engine. I'll work on getting the correct version of the files linked into a new project file, and send it to witchlord (it may not be today, tons of homework). Thanks again!

Quote:
Sorry to sound a little rude, but a you probably need to get a few tutorials or books on c++ programming first, how you will use c++ and bind c++ code on scripts when you dont know what a pointer is ?

No, you're right. However I DO know C++, it was just a stupid error on my part (declaring a pointer with out giving it something to point to). Sorry, I'm being defensive, it was a pretty dumb mistake.


[Edited by - Drakkcon on September 8, 2004 7:56:36 PM]

This topic is closed to new replies.

Advertisement