~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/3rdparty/squirrel/squirrel/sqdebug.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        see copyright notice in squirrel.h
 
3
*/
 
4
#include <squirrel.h>
 
5
#include "sqpcheader.h"
 
6
#include <stdarg.h>
 
7
#include "sqvm.h"
 
8
#include "sqfuncproto.h"
 
9
#include "sqclosure.h"
 
10
#include "sqstring.h"
 
11
 
 
12
SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
 
13
{
 
14
        SQInteger cssize = v->_callsstacksize;
 
15
        if (cssize > level) {
 
16
                memset(si, 0, sizeof(SQStackInfos));
 
17
                SQVM::CallInfo &ci = v->_callsstack[cssize-level-1];
 
18
                switch (type(ci._closure)) {
 
19
                case OT_CLOSURE:{
 
20
                        SQFunctionProto *func = _funcproto(_closure(ci._closure)->_function);
 
21
                        if (type(func->_name) == OT_STRING)
 
22
                                si->funcname = _stringval(func->_name);
 
23
                        if (type(func->_sourcename) == OT_STRING)
 
24
                                si->source = _stringval(func->_sourcename);
 
25
                        si->line = func->GetLine(ci._ip);
 
26
                                                }
 
27
                        break;
 
28
                case OT_NATIVECLOSURE:
 
29
                        si->source = _SC("NATIVE");
 
30
                        si->funcname = _SC("unknown");
 
31
                        if(type(_nativeclosure(ci._closure)->_name) == OT_STRING)
 
32
                                si->funcname = _stringval(_nativeclosure(ci._closure)->_name);
 
33
                        si->line = -1;
 
34
                        break;
 
35
                default: break; //shutup compiler
 
36
                }
 
37
                return SQ_OK;
 
38
        }
 
39
        return SQ_ERROR;
 
40
}
 
41
 
 
42
void SQVM::Raise_Error(const SQChar *s, ...)
 
43
{
 
44
        va_list vl;
 
45
        va_start(vl, s);
 
46
        scvsprintf(_sp(rsl((SQInteger)scstrlen(s)+(NUMBER_MAX_CHAR*2))), s, vl);
 
47
        va_end(vl);
 
48
        _lasterror = SQString::Create(_ss(this),_spval,-1);
 
49
}
 
50
 
 
51
void SQVM::Raise_Error(SQObjectPtr &desc)
 
52
{
 
53
        _lasterror = desc;
 
54
}
 
55
 
 
56
SQString *SQVM::PrintObjVal(const SQObject &o)
 
57
{
 
58
        switch(type(o)) {
 
59
        case OT_STRING: return _string(o);
 
60
        case OT_INTEGER:
 
61
#if defined(_SQ64)
 
62
                scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%ld"), _integer(o));
 
63
#else
 
64
                scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%d"), _integer(o));
 
65
#endif
 
66
                return SQString::Create(_ss(this), _spval);
 
67
                break;
 
68
        case OT_FLOAT:
 
69
                scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%.14g"), _float(o));
 
70
                return SQString::Create(_ss(this), _spval);
 
71
                break;
 
72
        default:
 
73
                return SQString::Create(_ss(this), GetTypeName(o));
 
74
        }
 
75
}
 
76
 
 
77
void SQVM::Raise_IdxError(SQObject &o)
 
78
{
 
79
        SQObjectPtr oval = PrintObjVal(o);
 
80
        Raise_Error(_SC("the index '%.50s' does not exist"), _stringval(oval));
 
81
}
 
82
 
 
83
void SQVM::Raise_CompareError(const SQObject &o1, const SQObject &o2)
 
84
{
 
85
        SQObjectPtr oval1 = PrintObjVal(o1), oval2 = PrintObjVal(o2);
 
86
        Raise_Error(_SC("comparsion between '%.50s' and '%.50s'"), _stringval(oval1), _stringval(oval2));
 
87
}
 
88
 
 
89
 
 
90
void SQVM::Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger type)
 
91
{
 
92
        SQObjectPtr exptypes = SQString::Create(_ss(this), _SC(""), -1);
 
93
        SQInteger found = 0;
 
94
        for(SQInteger i=0; i<16; i++)
 
95
        {
 
96
                SQInteger mask = 0x00000001 << i;
 
97
                if(typemask & (mask)) {
 
98
                        if(found>0) StringCat(exptypes,SQString::Create(_ss(this), _SC("|"), -1), exptypes);
 
99
                        found ++;
 
100
                        StringCat(exptypes,SQString::Create(_ss(this), IdType2Name((SQObjectType)mask), -1), exptypes);
 
101
                }
 
102
        }
 
103
        Raise_Error(_SC("parameter %d has an invalid type '%s' ; expected: '%s'"), nparam, IdType2Name((SQObjectType)type), _stringval(exptypes));
 
104
}