MCPcopy Create free account
hub / github.com/StrongPC123/Far-Cry-1-Source-Full / GetCallsStack

Method GetCallsStack

CryScriptSystem/ScriptSystem.cpp:136–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134#define LEVELS2 10 /* size of the second part of the stack */
135
136IScriptObject *CScriptSystem::GetCallsStack()
137{
138 Validate();
139 IScriptObject *pStackTrace=CreateObject();
140 int level = 0;
141 int firstpart = 1; /* still before eventual `...' */
142 lua_Debug ar;
143 while (lua_getstack(m_pLS, level++, &ar)) {
144
145 l_char buff[120]; /* enough to fit following `sprintf's */
146 if (level == 2)
147 {
148 //luaL_addstring(&b, l_s("stack traceback:\n"));
149 }
150 else if (level > LEVELS1 && firstpart)
151 {
152 /* no more than `LEVELS2' more levels? */
153 if (!lua_getstack(m_pLS, level+LEVELS2, &ar))
154 level--; /* keep going */
155 else {
156 // luaL_addstring(&b, l_s(" ...\n")); /* too many levels */
157 while (lua_getstack(m_pLS, level+LEVELS2, &ar)) /* find last levels */
158 level++;
159 }
160 firstpart = 0;
161 continue;
162 }
163
164 IScriptObject *pEntry=CreateObject();
165 sprintf(buff, l_s("%4d: "), level-1);
166
167 lua_getinfo(m_pLS, l_s("Snl"), &ar);
168 switch (*ar.namewhat)
169 {
170 case 'g': case 'l': /* global, local */
171 sprintf(buff, "function `%.50s'", ar.name);
172 break;
173 case 'f': /* field */
174 sprintf(buff, "method `%.50s'", ar.name);
175 break;
176 case 't': /* tag method */
177 sprintf(buff, "`%.50s' tag method", ar.name);
178 break;
179 default: {
180 if (*ar.what == 'm') /* main? */
181 sprintf(buff, "main of %.70s", ar.short_src);
182 else if (*ar.what == 'C') /* C function? */
183 sprintf(buff, "%.70s", ar.short_src);
184 else
185 sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.short_src);
186 }
187 }
188
189 pEntry->SetValue("description",buff);
190 pEntry->SetValue("line",ar.currentline);
191 if (ar.source) {
192 pEntry->SetValue("sourcefile",ar.source);
193 }

Callers 1

GetStackAndLocalsMethod · 0.80

Calls 5

lua_getstackFunction · 0.85
lua_getinfoFunction · 0.85
PushBackMethod · 0.80
SetValueMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected