🎉 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!

Error manually loading angelscript.dll [Solved]

Started by
7 comments, last by Blednik 17 years, 4 months ago
Hello. I was looking for a cool c++ style scripting language and I came across this Angelscript thing that looks very promising and I decided to give it a go. Now I'm not exactly sure whether I'm doing something wrong as I'm still learning C++, but the thing I'm working on won't compile in MSDEV (VC++ 6). I've managed to compile the lib and dll from the AngelScript 2.8.0a source code. Now my goal is to manually load the library into a C++ project. Now I've tried to do that by following some tutorials I've found on the angelcode website, but couldn't get it working. There is an article that nicely explains the whole process, but I can't get it to compile due to some compiler error even when using the exact example code. http://www.angelcode.com/angelscript/extras/articles/loadlib.html Compiling... lib.cpp D:\Visual C++\Programs\astest\lib.h(8) : error C2146: syntax error : missing ';' before identifier 't_asCreateScriptEngine' D:\Visual C++\Programs\astest\lib.h(8) : fatal error C1004: unexpected end of file found Error executing cl.exe. astest.exe - 2 error(s), 0 warning(s) I'm using the exact example code that I've copy/pasted from the article. Seems like MSDEV doesn't like these lines. Any ideas? // typedef the function interfaces typedef asIScriptEngine * AS_CALL t_asCreateScriptEngine(int); typedef const char * AS_CALL t_asGetLibraryVersion(); typedef asIScriptContext * AS_CALL t_asGetActiveContext(); [Edited by - Blednik on February 25, 2007 10:29:41 AM]
Advertisement
That article is a bit out of date. You'll have to change the words AS_CALL for AS_API.

I'll update the article with this information as well.

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

The file is exactly as shown on the bottom of the tutorial page - see link in my first post. PS. Are you sure it's AS_CALL and not AS_API?

#ifndef LIB_H
#define LIB_H

#define ANGELSCRIPT_DLL_MANUAL_IMPORT
#include "angelscript.h"

// typedef the function interfaces
typedef asIScriptEngine * AS_CALL t_asCreateScriptEngine(int);
typedef const char * AS_CALL t_asGetLibraryVersion();
typedef asIScriptContext * AS_CALL t_asGetActiveContext();

int LoadScriptLibrary();
void UnloadScriptLibrary();

extern t_asCreateScriptEngine *asCreateScriptEngine;
extern t_asGetLibraryVersion *asGetLibraryVersion;
extern t_asGetActiveContext *asGetActiveContext;

#endif
You're right. It should be AS_API instead of AS_CALL.

I edited my response before I saw that you had already responded. :)

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've updated the article. There were some other errors as well besides the AS_API one. It's been a long time since I removed the usage of __stdcall so the symbol names are without extra characters, i.e. no _ and no @4.

You may want to pick it up again.

Are you sure you need to use AngelScript from a dll? It's usually easier to use it from a static library.

With the dll you'll need to make sure that the memory management is done correctly. I suggest you register the memory functions with asSetGlobalMemoryFunctions(), otherwise you may end up mix up of memory allocations, i.e. memory allocated in the dll's heap being freed by the application or vice versa.

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

Thanks for confirming it. The articles should be updated to reflect that imo. I had to add two extra files to the project - bstr.h and bstr.cpp which I found in sdk\tests\test_feature\source. Added a '#include "lib.h"' line to bstr.cpp and now it compiles fine.


Running the program loads the library fine, but fails to return proper pointers to functions - they are null. Seems like I didn't compile the DLL properly. An earlier DLL that I downloaded worked fine. Partially. I wonder what I did wrong.

EDIT:
You updated while I was posting ;) I'll see what I can do. I'm not exactly sure if I want a DLL, but I'm only experimenting with it at this point. If I use a DLL I won't have to update my executable each time, but instead I could update angelscript.dll.
Cool it works now! The DLL seems to be compiled properly for that matter. I modified some lines in lib.cpp like you suggested and it works fine. I'll play around a bit.

asCreateScriptEngine = (t_asCreateScriptEngine*)GetProcAddress(dll, "asCreateScriptEngine");
asGetLibraryVersion = (t_asGetLibraryVersion*)GetProcAddress(dll, "asGetLibraryVersion");
asGetActiveContext = (t_asGetActiveContext*)GetProcAddress(dll, "asGetActiveContext");

PS. I have some technical questions. How fast really is angelscript compared to other game scripts (such as UnrealScript) and could I use it for a gameloop that runs about 70 times per second?
I cannot begin to guess how fast AngelScript is compared to UnrealScript, as UnrealScript is a proprietary script engine only used in Unreal. AngelScript has however been shown to be faster than Lua, Squirrel, and GameMonkey, all three of which are used in many commercial games.

You should be able to use AngelScript without problem within your game loop. Of course it depends on how much you want to do in scripting. The rule is to not do the heavy processing in the scripts (independently of which script library you choose to use). The scripts should mostly be used to make decisions and update the game state based on that, don't try to implement physics or pathfinding in the scripts as it will be way to slow. (though I'm sure you already know that)

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

Sounds good! Ty for all the answers :D

This topic is closed to new replies.

Advertisement