A bunch of questions
The SetGlobalMemoryFunctions call should be made before the script engine is created with asCreateScriptEngine, so that even the script engine itself is allocated using the proper routines.
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
In C/C++ you would simply declare a pointer like:
int* value = 0;
This is a null pointer and is not useful on its own, but you can assign the address of another variable to it. Like this:
int another_var;
value = &another_var;
Then if you plan to read/write stuff to that another variable, you would simply de-reference the pointer and do normal read/write.
(*value) = 300;
This is an example where you let the program assign the proper address of another_var to the value pointer, but you could also do it manually:
value = 0x00413590;
int result = (*value);
This would read whatever memory is being stored at the address 0x00413590 of the current process. Translation to assembly:
MOV ECX, 00413590
MOV EAX, DWORD PTR:[ECX]
So I was wondering whether AngelScript supports this kind of memory access or do I have to write two proxy functions in C/C++ - ReadMemory(int address, char * buffer, int length) and WriteMemory(int address, char * buffer, int length) and register those with the engine?
Sorry, if I wasn't being clear enough.
EDIT: Typo fix
You don't have to do anything special to have the DLL read or write memory in the application process. When the DLL is loaded by the application, it will share the same memory space as the application itself.
The DLL usually uses it's own memory heap though, a block of memory allocated in the application must not be deallocated by the DLL, and vice versa.
AngelScript doesn't however have any built-in functions for reading from or writing to random memory locations, as it's usually not something you would want to allow a script to do due to safety issues. If you need to do that, you would have to register a couple of functions to do it for you. Example:
int ReadFromMemory(int location){ return *(int*)location;}engine->RegisterGlobalFunction("int ReadFromMemory(int)", asFUNCTION(ReadFromMemory), asCALL_CDECL);
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Question 2:
You create an engine and configure it with a bunch of functions. Now it's time to add a couple of script sections to it. But suppose that something goes wrong after a number of sections have been added by AddScriptSection(...) e.g. a script seems corrupted. How would I remove all these script sections that have already been added so that I can begin anew? I've been poking through angelscript.h function prototypes and found this entry, could this be what I'm looking for?
virtual int ResetModule(const char *module) = 0;
Also, I assume the Discard(...) function is the opposite of Build(...), correct me, if I'm wrong. If yes, this answers another question I was about to ask.
You might want to check the manual for information on the interface methods. That way you don't have to try to guess your way by looking at the angelscript.h header 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
So you're saying I should use Build() to remove the previously added script sections to discard them?
EDIT: Let me sum up the whole story to show you what I'm trying to do here.
I have a script loader, kind of like the one in examples that handles #include directives. The thing is that I don't trust the directives to always be genuine. A user might put some corrupted data into one of the scripts or perhaps a script doesn't exist. The engine has already included a number of existing scripts and needs to stop. Now the user might fix the error and try to load the same scripts again... or, he might want to load a totally different script. In any way, the engine should be able to dump the previously loaded scripts and begin anew. My question is what is the proper way to do so.
[Edited by - Blednik on October 5, 2008 2:44:05 PM]
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
...
Maybe I should rephrase that question, assuming that Build() is the function that generates the bytecode...
When the user decides to load another script, does the previously built script need to be freed manually - e.g. Discard() - or can I just ignore it and do AddScriptSection() + Build() ontop of the existing bytecode, knowing it will be overwritten? The scripts use the same module.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game