Exception: Constructor now takes printf style arguments
This commit is contained in:
		
							parent
							
								
									5b736bcfd6
								
							
						
					
					
						commit
						9759e52b3c
					
				
					 7 changed files with 20 additions and 30 deletions
				
			
		| 
						 | 
					@ -94,9 +94,7 @@ void raiseRbExc(const Exception &exc)
 | 
				
			||||||
	RbData *data = getRbData();
 | 
						RbData *data = getRbData();
 | 
				
			||||||
	VALUE excClass = data->exc[excToRbExc[exc.type]];
 | 
						VALUE excClass = data->exc[excToRbExc[exc.type]];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static char buffer[512];
 | 
						rb_raise(excClass, exc.msg.c_str());
 | 
				
			||||||
	exc.snprintf(buffer, sizeof(buffer));
 | 
					 | 
				
			||||||
	rb_raise(excClass, buffer);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -275,9 +275,7 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	catch (const Exception &e)
 | 
						catch (const Exception &e)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		char buffer[512];
 | 
							readError = std::string(": ") + e.msg;
 | 
				
			||||||
		snprintf(buffer, sizeof(buffer), e.fmt.c_str(), e.arg1.c_str(), e.arg2.c_str());
 | 
					 | 
				
			||||||
		readError = std::string(": ") + std::string(buffer);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SDL_RWclose(&ops);
 | 
						SDL_RWclose(&ops);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -138,9 +138,7 @@ void raiseMrbExc(mrb_state *mrb, const Exception &exc)
 | 
				
			||||||
	MrbData *data = getMrbData(mrb);
 | 
						MrbData *data = getMrbData(mrb);
 | 
				
			||||||
	RClass *excClass = data->exc[excToMrbExc[exc.type]];
 | 
						RClass *excClass = data->exc[excToMrbExc[exc.type]];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static char buffer[512];
 | 
						mrb_raise(mrb, excClass, exc.msg.c_str());
 | 
				
			||||||
	exc.snprintf(buffer, sizeof(buffer));
 | 
					 | 
				
			||||||
	mrb_raise(mrb, excClass, buffer);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MRB_METHOD_PUB(inspectObject)
 | 
					MRB_METHOD_PUB(inspectObject)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -548,8 +548,8 @@ read_value(MarshalContext *ctx)
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	default :
 | 
						default :
 | 
				
			||||||
		throw Exception(Exception::MKXPError, "Marshal.load: unsupported value type '%s'",
 | 
							throw Exception(Exception::MKXPError, "Marshal.load: unsupported value type '%c'",
 | 
				
			||||||
		                std::string(1, (char)type));
 | 
							                (char) type);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mrb_gc_arena_restore(mrb, arena);
 | 
						mrb_gc_arena_restore(mrb, arena);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,6 +58,6 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Every cpp needs to define DISP_CLASS_NAME for itself (lowercase) */
 | 
					/* Every cpp needs to define DISP_CLASS_NAME for itself (lowercase) */
 | 
				
			||||||
#define GUARD_DISPOSED \
 | 
					#define GUARD_DISPOSED \
 | 
				
			||||||
{ if (isDisposed()) throw Exception(Exception::RGSSError, "disposed %S", DISP_CLASS_NAME); }
 | 
					{ if (isDisposed()) throw Exception(Exception::RGSSError, "disposed %s", DISP_CLASS_NAME); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // DISPOSABLE_H
 | 
					#endif // DISPOSABLE_H
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <stdarg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Exception
 | 
					struct Exception
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -44,19 +45,19 @@ struct Exception
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Type type;
 | 
						Type type;
 | 
				
			||||||
	std::string fmt;
 | 
						std::string msg;
 | 
				
			||||||
	std::string arg1;
 | 
					 | 
				
			||||||
	std::string arg2;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Exception(Type type, std::string fmt,
 | 
					 | 
				
			||||||
	          std::string arg1 = std::string(),
 | 
					 | 
				
			||||||
	          std::string arg2 = std::string())
 | 
					 | 
				
			||||||
	    : type(type), fmt(fmt), arg1(arg1), arg2(arg2)
 | 
					 | 
				
			||||||
	{}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void snprintf(char *buffer, size_t bufSize) const
 | 
						Exception(Type type, const char *format, ...)
 | 
				
			||||||
 | 
						    : type(type)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		::snprintf(buffer, bufSize, fmt.c_str(), arg1.c_str(), arg2.c_str());
 | 
							va_list ap;
 | 
				
			||||||
 | 
							va_start(ap, format);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							msg.resize(512);
 | 
				
			||||||
 | 
							vsnprintf(&msg[0], msg.size(), format, ap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							va_end(ap);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -128,15 +128,10 @@ TEXFBO TexPool::request(int width, int height)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int maxSize = glState.caps.maxTexSize;
 | 
						int maxSize = glState.caps.maxTexSize;
 | 
				
			||||||
	if (width > maxSize || height > maxSize)
 | 
						if (width > maxSize || height > maxSize)
 | 
				
			||||||
	{
 | 
							throw Exception(Exception::MKXPError,
 | 
				
			||||||
		char buffer[128];
 | 
					 | 
				
			||||||
		snprintf(buffer, sizeof(buffer),
 | 
					 | 
				
			||||||
		                "Texture dimensions [%d, %d] exceed hardware capabilities",
 | 
							                "Texture dimensions [%d, %d] exceed hardware capabilities",
 | 
				
			||||||
		                width, height);
 | 
							                width, height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		throw Exception(Exception::MKXPError, buffer);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Nope, create it instead */
 | 
						/* Nope, create it instead */
 | 
				
			||||||
	TEXFBO::init(cnode.obj);
 | 
						TEXFBO::init(cnode.obj);
 | 
				
			||||||
	TEXFBO::allocEmpty(cnode.obj, width, height);
 | 
						TEXFBO::allocEmpty(cnode.obj, width, height);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue