Changeset - r25705:db1afb7a7392
[Not reviewed]
master
0 7 0
Rubidium - 3 years ago 2021-06-16 19:10:41
rubidium@openttd.org
Cleanup: [Script] Use nullptr instead of 0 or NULL
7 files changed with 16 insertions and 16 deletions:
0 comments (0 inline, 0 general)
cmake/scripts/SquirrelExport.cmake
Show inline comments
 
@@ -25,16 +25,16 @@ macro(dump_fileheader)
 
    endif()
 
endmacro()
 

	
 
macro(dump_class_templates NAME)
 
    string(REGEX REPLACE "^Script" "" REALNAME ${NAME})
 

	
 
    string(APPEND SQUIRREL_EXPORT "\n	template <> inline ${NAME} *GetParam(ForceType<${NAME} *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (${NAME} *)instance; }")
 
    string(APPEND SQUIRREL_EXPORT "\n	template <> inline ${NAME} &GetParam(ForceType<${NAME} &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(${NAME} *)instance; }")
 
    string(APPEND SQUIRREL_EXPORT "\n	template <> inline const ${NAME} *GetParam(ForceType<const ${NAME} *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (${NAME} *)instance; }")
 
    string(APPEND SQUIRREL_EXPORT "\n	template <> inline const ${NAME} &GetParam(ForceType<const ${NAME} &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(${NAME} *)instance; }")
 
    string(APPEND SQUIRREL_EXPORT "\n	template <> inline ${NAME} *GetParam(ForceType<${NAME} *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, nullptr); return  (${NAME} *)instance; }")
 
    string(APPEND SQUIRREL_EXPORT "\n	template <> inline ${NAME} &GetParam(ForceType<${NAME} &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, nullptr); return *(${NAME} *)instance; }")
 
    string(APPEND SQUIRREL_EXPORT "\n	template <> inline const ${NAME} *GetParam(ForceType<const ${NAME} *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, nullptr); return  (${NAME} *)instance; }")
 
    string(APPEND SQUIRREL_EXPORT "\n	template <> inline const ${NAME} &GetParam(ForceType<const ${NAME} &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, nullptr); return *(${NAME} *)instance; }")
 
    if("${NAME}" STREQUAL "ScriptEvent")
 
        string(APPEND SQUIRREL_EXPORT "\n	template <> inline int Return<${NAME} *>(HSQUIRRELVM vm, ${NAME} *res) { if (res == nullptr) { sq_pushnull(vm); return 1; } Squirrel::CreateClassInstanceVM(vm, \"${REALNAME}\", res, nullptr, DefSQDestructorCallback<${NAME}>, true); return 1; }")
 
    elseif("${NAME}" STREQUAL "ScriptText")
 
        string(APPEND SQUIRREL_EXPORT "\n")
 
        string(APPEND SQUIRREL_EXPORT "\n	template <> inline Text *GetParam(ForceType<Text *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) {")
 
        string(APPEND SQUIRREL_EXPORT "\n		if (sq_gettype(vm, index) == OT_INSTANCE) {")
src/ai/ai_info.cpp
Show inline comments
 
@@ -60,13 +60,13 @@ template <> const char *GetClassName<AII
 
}
 

	
 
/* static */ SQInteger AIInfo::Constructor(HSQUIRRELVM vm)
 
{
 
	/* Get the AIInfo */
 
	SQUserPointer instance = nullptr;
 
	if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == nullptr) return sq_throwerror(vm, "Pass an instance of a child class of AIInfo to RegisterAI");
 
	if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, nullptr)) || instance == nullptr) return sq_throwerror(vm, "Pass an instance of a child class of AIInfo to RegisterAI");
 
	AIInfo *info = (AIInfo *)instance;
 

	
 
	SQInteger res = ScriptInfo::Constructor(vm, info);
 
	if (res != 0) return res;
 

	
 
	ScriptConfigItem config = _start_date_config;
 
@@ -104,13 +104,13 @@ template <> const char *GetClassName<AII
 
}
 

	
 
/* static */ SQInteger AIInfo::DummyConstructor(HSQUIRRELVM vm)
 
{
 
	/* Get the AIInfo */
 
	SQUserPointer instance;
 
	sq_getinstanceup(vm, 2, &instance, 0);
 
	sq_getinstanceup(vm, 2, &instance, nullptr);
 
	AIInfo *info = (AIInfo *)instance;
 
	info->api_version = nullptr;
 

	
 
	SQInteger res = ScriptInfo::Constructor(vm, info);
 
	if (res != 0) return res;
 

	
src/game/game_info.cpp
Show inline comments
 
@@ -51,13 +51,13 @@ template <> const char *GetClassName<Gam
 
}
 

	
 
/* static */ SQInteger GameInfo::Constructor(HSQUIRRELVM vm)
 
{
 
	/* Get the GameInfo */
 
	SQUserPointer instance = nullptr;
 
	if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == nullptr) return sq_throwerror(vm, "Pass an instance of a child class of GameInfo to RegisterGame");
 
	if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, nullptr)) || instance == nullptr) return sq_throwerror(vm, "Pass an instance of a child class of GameInfo to RegisterGame");
 
	GameInfo *info = (GameInfo *)instance;
 

	
 
	SQInteger res = ScriptInfo::Constructor(vm, info);
 
	if (res != 0) return res;
 

	
 
	if (info->engine->MethodExists(*info->SQ_instance, "MinVersionToLoad")) {
src/script/api/script_text.cpp
Show inline comments
 
@@ -106,13 +106,13 @@ SQInteger ScriptText::_SetParam(int para
 
			sq_get(vm, -2);
 
			sq_pushobject(vm, instance);
 
			if (sq_instanceof(vm) != SQTrue) return SQ_ERROR;
 
			sq_pop(vm, 3);
 

	
 
			/* Get the 'real' instance of this class */
 
			sq_getinstanceup(vm, -1, &real_instance, 0);
 
			sq_getinstanceup(vm, -1, &real_instance, nullptr);
 
			if (real_instance == nullptr) return SQ_ERROR;
 

	
 
			ScriptText *value = static_cast<ScriptText *>(real_instance);
 
			value->AddRef();
 
			this->paramt[parameter] = value;
 
			break;
src/script/squirrel.cpp
Show inline comments
 
@@ -253,13 +253,13 @@ void Squirrel::RunError(HSQUIRRELVM vm, 
 
	/* Reset the old print function */
 
	sq_setprintfunc(vm, pf);
 
}
 

	
 
SQInteger Squirrel::_RunError(HSQUIRRELVM vm)
 
{
 
	const SQChar *sErr = 0;
 
	const SQChar *sErr = nullptr;
 

	
 
	if (sq_gettop(vm) >= 1) {
 
		if (SQ_SUCCEEDED(sq_getstring(vm, -1, &sErr))) {
 
			Squirrel::RunError(vm, sErr);
 
			return 0;
 
		}
src/script/squirrel.hpp
Show inline comments
 
@@ -187,13 +187,13 @@ public:
 

	
 
	/**
 
	 * Get the real-instance pointer.
 
	 * @note This will only work just after a function-call from within Squirrel
 
	 *  to your C++ function.
 
	 */
 
	static bool GetRealInstance(HSQUIRRELVM vm, SQUserPointer *ptr) { return SQ_SUCCEEDED(sq_getinstanceup(vm, 1, ptr, 0)); }
 
	static bool GetRealInstance(HSQUIRRELVM vm, SQUserPointer *ptr) { return SQ_SUCCEEDED(sq_getinstanceup(vm, 1, ptr, nullptr)); }
 

	
 
	/**
 
	 * Get the Squirrel-instance pointer.
 
	 * @note This will only work just after a function-call from within Squirrel
 
	 *  to your C++ function.
 
	 */
src/script/squirrel_helper.hpp
Show inline comments
 
@@ -751,15 +751,15 @@ namespace SQConvert {
 
		sq_get(vm, -2);
 
		sq_pushobject(vm, instance);
 
		if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, "class method is non-static");
 
		sq_pop(vm, 3);
 

	
 
		/* Get the 'real' instance of this class */
 
		sq_getinstanceup(vm, 1, &real_instance, 0);
 
		sq_getinstanceup(vm, 1, &real_instance, nullptr);
 
		/* Get the real function pointer */
 
		sq_getuserdata(vm, nparam, &ptr, 0);
 
		sq_getuserdata(vm, nparam, &ptr, nullptr);
 
		if (real_instance == nullptr) return sq_throwerror(vm, "couldn't detect real instance of class for non-static call");
 
		/* Remove the userdata from the stack */
 
		sq_pop(vm, 1);
 

	
 
		try {
 
			/* Delegate it to a template that can handle this specific function */
 
@@ -793,15 +793,15 @@ namespace SQConvert {
 
		sq_get(vm, -2);
 
		sq_pushobject(vm, instance);
 
		if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, "class method is non-static");
 
		sq_pop(vm, 3);
 

	
 
		/* Get the 'real' instance of this class */
 
		sq_getinstanceup(vm, 1, &real_instance, 0);
 
		sq_getinstanceup(vm, 1, &real_instance, nullptr);
 
		/* Get the real function pointer */
 
		sq_getuserdata(vm, nparam, &ptr, 0);
 
		sq_getuserdata(vm, nparam, &ptr, nullptr);
 
		if (real_instance == nullptr) return sq_throwerror(vm, "couldn't detect real instance of class for non-static call");
 
		/* Remove the userdata from the stack */
 
		sq_pop(vm, 1);
 

	
 
		/* Call the function, which its only param is always the VM */
 
		return (SQInteger)(((Tcls *)real_instance)->*(*(Tmethod *)ptr))(vm);
 
@@ -817,13 +817,13 @@ namespace SQConvert {
 
	{
 
		/* Find the amount of params we got */
 
		int nparam = sq_gettop(vm);
 
		SQUserPointer ptr = nullptr;
 

	
 
		/* Get the real function pointer */
 
		sq_getuserdata(vm, nparam, &ptr, 0);
 
		sq_getuserdata(vm, nparam, &ptr, nullptr);
 

	
 
		try {
 
			/* Delegate it to a template that can handle this specific function */
 
			return HelperT<Tmethod>::SQCall((Tcls *)nullptr, *(Tmethod *)ptr, vm);
 
		} catch (SQInteger &e) {
 
			return e;
 
@@ -841,13 +841,13 @@ namespace SQConvert {
 
	{
 
		/* Find the amount of params we got */
 
		int nparam = sq_gettop(vm);
 
		SQUserPointer ptr = nullptr;
 

	
 
		/* Get the real function pointer */
 
		sq_getuserdata(vm, nparam, &ptr, 0);
 
		sq_getuserdata(vm, nparam, &ptr, nullptr);
 
		/* Remove the userdata from the stack */
 
		sq_pop(vm, 1);
 

	
 
		/* Call the function, which its only param is always the VM */
 
		return (SQInteger)(*(*(Tmethod *)ptr))(vm);
 
	}
0 comments (0 inline, 0 general)