simple scriptstdstring.cpp patch

Started by
6 comments, last by Aperion 14 years, 11 months ago
Hello all I have been working on the Rigs of Rods project using x86_64 on Kubuntu 9.04. I had to make a simple change to get Angelscript to compile. Sorry I don't have the exact error message but it complained that strstr (not found/defined/etc) below is the generated patch for the change
diff -U 3 -H -d -r -N -- sdk/add_on/scriptstdstring/scriptstdstring.cpp sdk-org/add_on/scriptstdstring/scriptstdstring.cpp
--- sdk/add_on/scriptstdstring/scriptstdstring.cpp	2009-05-03 10:13:56.502067157 -0700
+++ sdk-org/add_on/scriptstdstring/scriptstdstring.cpp	2009-05-03 10:18:33.990322811 -0700
@@ -455,7 +455,7 @@
 
 void RegisterStdString(asIScriptEngine * engine)
 {
-	if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY"))
+	if (string((asGetLibraryOptions()).find("AS_MAX_PORTABILITY") != string::npos)
 		RegisterStdString_Generic(engine);
 	else
 		RegisterStdString_Native(engine);



Advertisement
I find it hard to believe that strstr() isn't available, as it is a standard C function. Rather than changing the code to use std::string::find(), could you help me determine what would be the correct header file to include for the strstr() function?

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

According to the C standard, strstr() is in string.h.
Yes. Thanks.

I'd still prefer if Aperion could confirm that adding #include <string.h> fixes the problem he had though.

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

Quote:Original post by WitchLord
Yes. Thanks.

I'd still prefer if Aperion could confirm that adding #include <string.h> fixes the problem he had though.


I tried it multiple ways #include <cstring> works and #include <string.h> Would cstring be the more appropriate way for c++?
I really can't say. But if #include <string.h> works then that's what I'll do. This is what I have in the other add-ons anyway, I guess I just forgot to add it to this one.

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

According to the C++ standard, if you include cstring, then it takes all the functions and puts them in the std namespace without putting them in the root namespace. If you include string.h then it puts the functions in both the root namespace and the std namespace. In practice, pretty much every compiler puts the functions in both if you include cstring, with the one exception I know of being Borland's C++ compilers, which only puts the functions in the std namespace. This basically means that string.h is the right choice if you don't want to prefix everything with std::.
Quote:Original post by SiCrane
According to the C++ standard, if you include cstring, then it takes all the functions and puts them in the std namespace without putting them in the root namespace. If you include string.h then it puts the functions in both the root namespace and the std namespace. In practice, pretty much every compiler puts the functions in both if you include cstring, with the one exception I know of being Borland's C++ compilers, which only puts the functions in the std namespace. This basically means that string.h is the right choice if you don't want to prefix everything with std::.


ok, thanks for the explanation

This topic is closed to new replies.

Advertisement