Advertisement

Help! How to register this function?

Started by June 16, 2006 02:30 AM
9 comments, last by unk1024 18 years, 5 months ago
Sorry, my english is bad... How to pass "SendMessage" to and from AngelScript? void SendMessage (uint uEntityId, string sFormat, ...) I have the function "SendMessage" in my engine, which must be registered in AngelScript with unknown number of parameters, which have unknown types for me. Formates list (for sFormat): s - string type; f - float type; i - integer type; ... For example:

uint uEntityId = CreateEntity ("car");

...
string sName = "MyCar";

int nWidth = 100;
int nLength = 120;
int nHeight = 50;

float fSpeed = 121.5;

SendMessage (uEntityId, "isiiif", MSG_CREATE_GEOM_OBJECT, sName, nWidth, nLength, nHeight, fSpeed);
SendMessage (uEntityId, "is", MSG_SHOW_OBJECT, sName);
How to register this function? I tried to modify AngelScript's source code for adding "..."-type (as "va_list" in C++), but... :( I'm really sad. Thanks
Yeah! I rewrote my modified code of AngelScript and... it give me a good results. =) Now my little modified version of AngelScript support a floating arguments and I can register functions with the "...".

Thanks.
Advertisement
Why not share the code with us?
Sorry. I find a bug... As soon as I shall correct it I shall show a code.

[edit]
Damn! Why AngelScript doesn't register a global function which take two or more string type parameters and they aren't refs?
[/edit]
I haven't implemented support for variable parameters in AngelScript myself yet because it is not safe in a script environment. For C++ it is ok as the programmer is responsible for what he's doing, but for a script language you normally do not want to put that responsibility on the script writer as he/she might crash the application without knowing why.

Still, if you need this I may be able to help you with your customization of AngelScript. What are the problems you're encountering?

Quote:
Damn! Why AngelScript doesn't register a global function which take two or more string type parameters and they aren't refs?


What do you mean with this?

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

void SimpleFunction (std :: string a, std :: string b)
{
...
}

void CScriptEngineWrapper :: Register ()
{
CHECK_ERR (m_pEngine->RegisterGlobalFunction ("void SimpleFunction(string a, string b, ...)", asFUNCTION (SimpleFunction), asCALL_CDECL));
}

It will crash...

Next..

I read the AngelScript's source code where opcodes are execute and one moment point my attention (opcode: BC_STR). There we push the string pointer on the stack and save the string's length. But the stack pointer doesn't moved, i.e. next string push the length on the same position. It is a bug or it is a design feature?

Thank you. I think that you are right, but I need in this feature. I think that in my code there are something wrong, but it work.

URL:
http://slil.ru/22849508

My code are marked by such comment (sorry, but my small comments are in Russian, but it is not so important):

// unk1024:// ???


Can you add support of this feature in the following release of AngelScript (with use of definitions, for example, AS_FLOATING_ARGS_SUPPORT?). I think that it will be better if you will write the code of this feature because you is author AngelScript, which is the best scripting language =)

Thanks.
Advertisement
A also think it a good idea to add support for variable length parameters with a preprocess definition or even a runtime variable (pEngine->EnableVariableLength(true); ?)
why don't you use a list ?

string param1;
int param2;
...

list.add(param1);
list.add(param2);
...

SendMessage(uEntityId, "isiiif", MSG_CREATE_GEOM_OBJECT, list);

I agree it's not optimized vs ... call but it works !

AbrKen.
I tried to use list. But... How to create a list which take various types of parameters?
where is the problem ?

registering in AS the same function with different signatures ?
creating a list object in C++ witch take anykind of parameters type ?

AbrKen.

This topic is closed to new replies.

Advertisement