🎉 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!

example of passing pointer in AS function...?

Started by
2 comments, last by WitchLord 19 years, 5 months ago
hi guys, I want to be able to do the following: // Angelscript void DoSomething() { Menu Main; Main.AddMenu("Some_Name"); } Where AddMenu is as such: void CMenuHandler::AddMenu( char* pName ) { ... } I can register the object and method fine is there are no parameters (and it works), but having a poiinter as a parameter is returning an error on registering and building the script...... Can someone give me an example on how to register char* or equivalents and using them as parameters in member functions?? Nice one!
Advertisement
Pointers are not available in the script language. It is possible to register a string type that can be passed to application functions expecting a char* (look at test_feature/source/bstr.cpp), though I recommend that you instead use std::string as it is much easier to use. Register the string type with RegisterStdString() from add_on/std_string/stdstring.cpp, then register your class method as follows:

void CMenuHandler::AddMenu(string &str){  // do something with the string}engine->RegisterObjectMethod("Menu", "void AddMenu(string ∈)", asMETHOD(CMenuHandler, AddMenu), asCALL_THISCALL);


If you do not want to rewrite your existing CMenuHandler class, you could write a simple wrapper function as follows:

void CMenuHandler_AddMenu(string &str, CMenuHandler &menu){  menu.AddMenu(str.c_str());}engine->RegisterObjectMethod("Menu", "void AddMenu(string ∈)", asFUNCTION(CMenuHandler_AddMenu), asCALL_CDECL_OBJLAST);


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

stdstring.cpp wont link, says somethin about _errno unresovlved symbol and a couple of other unresolved stuff....


Linking...
Creating library Debug/pShell.lib and object Debug/pShell.exp
libcpd.lib(_tolower.obj) : error LNK2001: unresolved external symbol ___mb_cur_max
libcpd.lib(_toupper.obj) : error LNK2001: unresolved external symbol ___mb_cur_max
libcpd.lib(xwctomb.obj) : error LNK2001: unresolved external symbol _errno
Debug/pShell.exe : fatal error LNK1120: 2 unresolved externals

any ideas?
It looks like the linker isn't using the correct type standard C/C++ libraries. Make sure you compile the AS library and your application with the same settings, i.e. multi-threaded dll, static single threaded, debug libraries, etc.

What compiler are you using?

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