User data

Started by
25 comments, last by SiCrane 15 years, 5 months ago
A couple questions: is there an equivalent for SetUserData()/GetUserData() for asIScriptEngine? Also, for asIScriptContext, is there a way to register a function to cleanup user data when the context is destroyed?
Advertisement
No, there is currently no support for this.

However, these are good ideas that I'll add to the to-do list.

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, but I have another question: is there any way to map a type id from GetVarTypeId() to the actual type for primitives? Right now it seems like the type ids depend on what types show up first when scripts are compiled. To put things in context, I decided to see how using AngelScript from .NET would work out and for a proof on concept application I choose to make the world's most primitive debugger. So if I use this script:
int calc(int a, float b) {  print("Received: " + a + ", " + b + "\n");  return a * b;}void main() {  calc(3, 2);}

a shows up with type id of 1 and b shows up with a type id of 2. If I swap things around
int calc(float a, int b)

a shows up with a type id of 2 and b shows up with a type id of 1... until I restart the application, and then a becomes 1 and b becomes 2 again.

For reference, the MSVS 2008 solution for this project is available here. (It requires the addition of SetUserData()/GetUserData() to asIScriptEngine (included in the project) as well as Scintilla.NET.)
The idea is that you should compare the type id from GetVarTypeId with the result from GetTypeIdByDecl, alternatively call GetTypeDeclaration and compare the names of the types.

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

GetTypeDeclaration() looks like just what I needed. Thanks.
Ok, another question on this topic: is there any way to tell if a local variable has been constructed yet in a line callback or suspended thread?
AngelScript currently does not keep the scope of the variables in the functions, so there is no direct way of knowing if the variable has been constructed yet.

All object type variables are however null until they have been constructed, so that might help a bit.

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

Yeah, that should help. Thanks.
Last two for today, I promise: Is there an equivalent of GetVarTypeId() for globals or do I have to parse the result from GetGlobalVarDeclaration()? Also, if I have a type Object registered as a value type, why does GetVarPointer() return an Object ** instead of an Object *?
AngelScript is currently missing a GetGlobalVarTypeId. I just forgot to add this one, I'll do that for version 2.15.0.

You can however get the type by id by calling GetTypeIdByDecl(GetGlobalVarDeclaration()).

Currently AngelScript stores all registered types on the heap, whether they are value types or reference types. This is going to change in the near future (will improve both memory footprint and performance).

I'll also do with GetVarPointer what I did with GetGlobalVarPointer, i.e. deprecate it and create a GetAddressOfVar instead. GetAddressOfVar will return the address of the object directly, in the case of value types.

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

This topic is closed to new replies.

Advertisement