🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

how can i register object methods with a parameter " const char * "

Started by
17 comments, last by WitchLord 3 years, 5 months ago

xfcanyue said:
DrawText(a); //error

DrawText(@a); //error

Both of these are correct. They are actually mean the same thing. Since the method DrawText expects a handle the compiler will implicitly add the @ so you don't need to do it explicitly.

Can you explain what error you are getting?

Are you using reference counting on your objects, if so you need to register the ADDREF and RELEASE behaviours so the ref counter is properly updated. If you don't, then you need to register the object type with asOBJ_NOCOUNT (beware that you will have to control the memory management in some other way).

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

Advertisement

hi, Good evening.

messge = No matching singnatures to DrawText(ClassA @&).
yes, they are all asOBJ_NOCOUNT. above code, Just an example.

Why would the error be referring to “ClassA” with capital C, if you registered the type as “classA” with a small c? Are you mixing things up?

Can you show me a more complete code to reproduce the problem? It's difficult to help you if I have to guess on what exactly you are doing.

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

Sorry, it is clerical error.
In fact,
messge = No matching singnatures to DrawText(classA @&).

I've passed the code to GitHub:
https://github.com/xfcanyue/DuiLib_DuiEditor

I see your code.

REG_GLOBAL_FUNPR(void, CRenderEngine::DrawText, (HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText,DWORD dwTextColor, int iFont, UINT uStyle, DWORD dwTextBKColor));

If I understood REG_GLOBAL_FUNPR correctly this would register the function as “void DrawText(HDC, CPointManagerUI @, RECT&, LPCTSTR, DWORD, int, UINT, DWORD)”, which is OK.

However, it is clearly not the same as in your question before. Can you show me the real script with the real error message so I can help you better?

Or even better, write a small code snippet that reproduces the problem you have, without requiring the full code from your program, and we can discuss over that instead.

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

i'm so stupid, i find it, the error is “const RECT &rc” convert to “RECT &rc”.
the error message = No maching signatures to ‘DrawText(HDC&, CPaintManaerUI@&, const RECT &, ….)’;

when i try to write a small code snippet, i try,
std::string classname = "classB";
std::string factoryName = classname; factoryName += "@ f()";
std::string factoryFunc = classname; factoryFunc += "_Ref_Factory";
r = engine->RegisterObjectBehaviour(classname, asBEHAVE_FACTORY, factoryName.c_str(), asFUNCTION(factoryFunc.c_str()), asCALL_CDECL); assert( r >= 0 );
this code can be compiled, but no mistakes happened, maybe angelscript can't find this mistake.

Thank you very much.

Have you complied my poject on github?
It's an source editor, and contains a angelscript editor.
syntax tips. while move mouse on a function, call tips window to show function's declaration. but the paramters just type, have not name.

xfcanyue said:
this code can be compiled, but no mistakes happened, maybe angelscript can't find this mistake.

In your code you're giving the address of a string to asFUNCTION as if it was a function. It won't give a compilation error since it just just a pointer and it can be cast to a function pointer in C++, but it will certainly crash the application when the factory behaviour is called from the script.

xfcanyue said:
Have you complied my poject on github?

No I didn't attempt to compile your project. But the code looks neat and well made.

I wish I could read Chinese ? so I could understand the comments in the code.

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