Files
@ r27407:1787a47352b7
Branch filter:
Location: cpp/openttd-patchpack/source/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp - annotation
r27407:1787a47352b7
3.6 KiB
text/x-c
Codechange: prevent using (f)printf/(f)puts over fmt::print
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | r11225:37853e3b55c7 r21645:df9d17bb2041 r21645:df9d17bb2041 r21645:df9d17bb2041 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r21645:df9d17bb2041 r21645:df9d17bb2041 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r12720:caac4e91000e r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r25706:50b894f19d99 r11225:37853e3b55c7 r21642:d4ee019baf14 r11225:37853e3b55c7 r11225:37853e3b55c7 r21642:d4ee019baf14 r21642:d4ee019baf14 r11225:37853e3b55c7 r14580:5b7b7b861d6e r14580:5b7b7b861d6e r14580:5b7b7b861d6e r14580:5b7b7b861d6e r14580:5b7b7b861d6e r21643:d84f88897769 r21643:d84f88897769 r14580:5b7b7b861d6e r14580:5b7b7b861d6e r14580:5b7b7b861d6e r14580:5b7b7b861d6e r14580:5b7b7b861d6e r14580:5b7b7b861d6e r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r21642:d4ee019baf14 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r12720:caac4e91000e r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r25706:50b894f19d99 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r22366:969fbc66a51e r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r27143:ecee9375b5d4 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 r11225:37853e3b55c7 | /* see copyright notice in squirrel.h */
#include "../../../stdafx.h"
#include <squirrel.h>
#include <sqstdaux.h>
#include "../../fmt/format.h"
#include "../../../safeguards.h"
void sqstd_printcallstack(HSQUIRRELVM v)
{
SQPRINTFUNCTION pf = sq_getprintfunc(v);
if(pf) {
SQStackInfos si;
SQInteger i;
SQBool b;
SQFloat f;
const SQChar *s;
SQInteger level=1; //1 is to skip this function that is level 0
const SQChar *name=nullptr;
SQInteger seq=0;
pf(v,"\nCALLSTACK\n");
while(SQ_SUCCEEDED(sq_stackinfos(v,level,&si)))
{
const SQChar *fn="unknown";
const SQChar *src="unknown";
if(si.funcname)fn=si.funcname;
if(si.source) {
/* We don't want to bother users with absolute paths to all AI files.
* Since the path only reaches NoAI code in a formatted string we have
* to strip it here. Let's hope nobody installs openttd in a subdirectory
* of a directory named /ai/. */
src = strstr(si.source, "\\ai\\");
if (!src) src = strstr(si.source, "/ai/");
if (src) {
src += 4;
} else {
src = si.source;
}
}
pf(v,fmt::format("*FUNCTION [{}()] {} line [{}]\n",fn,src,si.line));
level++;
}
level=0;
pf(v,"\nLOCALS\n");
for(level=0;level<10;level++){
seq=0;
while((name = sq_getlocal(v,level,seq)))
{
seq++;
switch(sq_gettype(v,-1))
{
case OT_NULL:
pf(v,fmt::format("[{}] NULL\n",name));
break;
case OT_INTEGER:
sq_getinteger(v,-1,&i);
pf(v,fmt::format("[{}] {}\n",name,i));
break;
case OT_FLOAT:
sq_getfloat(v,-1,&f);
pf(v,fmt::format("[{}] {:14g}\n",name,f));
break;
case OT_USERPOINTER:
pf(v,fmt::format("[{}] USERPOINTER\n",name));
break;
case OT_STRING:
sq_getstring(v,-1,&s);
pf(v,fmt::format("[{}] \"{}\"\n",name,s));
break;
case OT_TABLE:
pf(v,fmt::format("[{}] TABLE\n",name));
break;
case OT_ARRAY:
pf(v,fmt::format("[{}] ARRAY\n",name));
break;
case OT_CLOSURE:
pf(v,fmt::format("[{}] CLOSURE\n",name));
break;
case OT_NATIVECLOSURE:
pf(v,fmt::format("[{}] NATIVECLOSURE\n",name));
break;
case OT_GENERATOR:
pf(v,fmt::format("[{}] GENERATOR\n",name));
break;
case OT_USERDATA:
pf(v,fmt::format("[{}] USERDATA\n",name));
break;
case OT_THREAD:
pf(v,fmt::format("[{}] THREAD\n",name));
break;
case OT_CLASS:
pf(v,fmt::format("[{}] CLASS\n",name));
break;
case OT_INSTANCE:
pf(v,fmt::format("[{}] INSTANCE\n",name));
break;
case OT_WEAKREF:
pf(v,fmt::format("[{}] WEAKREF\n",name));
break;
case OT_BOOL:{
sq_getbool(v,-1,&b);
pf(v,fmt::format("[{}] {}\n",name,b?"true":"false"));
}
break;
default: assert(0); break;
}
sq_pop(v,1);
}
}
}
}
static SQInteger _sqstd_aux_printerror(HSQUIRRELVM v)
{
SQPRINTFUNCTION pf = sq_getprintfunc(v);
if(pf) {
const SQChar *sErr = nullptr;
if(sq_gettop(v)>=1) {
if(SQ_SUCCEEDED(sq_getstring(v,2,&sErr))) {
pf(v,fmt::format("\nAN ERROR HAS OCCURRED [{}]\n",sErr));
}
else{
pf(v,"\nAN ERROR HAS OCCURRED [unknown]\n");
}
sqstd_printcallstack(v);
}
}
return 0;
}
void _sqstd_compiler_error(HSQUIRRELVM v,const SQChar *sErr,const SQChar *sSource,SQInteger line,SQInteger column)
{
SQPRINTFUNCTION pf = sq_getprintfunc(v);
if(pf) {
pf(v,fmt::format("{} line = ({}) column = ({}) : error {}\n",sSource,line,column,sErr));
}
}
void sqstd_seterrorhandlers(HSQUIRRELVM v)
{
sq_setcompilererrorhandler(v,_sqstd_compiler_error);
sq_newclosure(v,_sqstd_aux_printerror,0);
sq_seterrorhandler(v);
}
|