t_img* img_new_tga (char *fname)
engine->RegisterGlobalFunction("t_img *img_new_tga(bstr)", asFUNCTION(img_new_tga), asCALL_CDECL);
This should let you write your script like this:
tga = img_new_tga("reflect.tga");
BSTR is typedefed as (unsigned char *) so that it can be sent to functions taking a (char *) directly.
As to your other question. The behaviour is expected, since your bstr_to_int8() function takes a non const reference. Simply declare the parameter as const and you should be able to call it with a constant directly.
Currently the bstr needs to be handled with care. This is because AngelScript has to manage the memory allocated for the strings. Thus there are a few rules that you ought to follow or you''ll get memory leaks:
- When receiving an asBSTR by value, you must free the memory before returning from the function. Call asBStrFree()
- When returning an new asBSTR to the script engine it must be allocated with asBStrAlloc()
- When receiving an asBSTR & or an asBSTR * you don''t have to free the memory since the script engine is still holding a reference to it
- If you receive an asBSTR *, and need to change the string it points to call asBStrAlloc() for the new string, and asBStrFree() on the old string.
In a future version I will break out the implementation of asBSTR from the script engine so that each application can decide how they are handled. Of course I will make the functions needed to make the asBSTR work as normal available to the public for free.
- game development and more...AngelScript
- free scripting library