Sign in to follow this  

Help! How to register this function?

This topic is 4199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this