OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4AulScriptFunc.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #include "C4Include.h"
17 #include "script/C4AulScriptFunc.h"
18 
19 #include "script/C4AulExec.h"
20 #include "script/C4ScriptHost.h"
21 
22 C4AulScriptFunc::C4AulScriptFunc(C4PropListStatic * Parent, C4ScriptHost *pOrgScript, const char *pName, const char *Script):
23  C4AulFunc(Parent, pName),
24  OwnerOverloaded(nullptr),
25  ParCount(0),
26  Script(Script),
27  pOrgScript(pOrgScript),
28  tProfileTime(0)
29 {
30  for (int i = 0; i < C4AUL_MAX_Par; i++) ParType[i] = C4V_Any;
31  AddBCC(AB_EOFN);
32 }
33 
35  C4AulFunc(Parent, FromFunc.GetName()),
36  OwnerOverloaded(nullptr),
37  ParCount(FromFunc.ParCount),
38  Script(FromFunc.Script),
39  VarNamed(FromFunc.VarNamed),
40  ParNamed(FromFunc.ParNamed),
41  pOrgScript(FromFunc.pOrgScript),
42  tProfileTime(0)
43 {
44  for (int i = 0; i < C4AUL_MAX_Par; i++)
45  ParType[i] = FromFunc.ParType[i];
46  AddBCC(AB_EOFN);
47 }
48 
50 {
52  ClearCode();
53 }
54 
56 {
58  OwnerOverloaded = f;
59  if (f) f->IncRef();
60 }
61 
62 void C4AulScriptFunc::AddBCC(C4AulBCCType eType, intptr_t X, const char * SPos)
63 {
64  // store chunk
65  Code.emplace_back(eType, X);
66  PosForCode.push_back(SPos);
67 }
68 
70 {
71  Code.pop_back();
72  PosForCode.pop_back();
73 }
74 
76 {
77  while(Code.size() > 0)
78  RemoveLastBCC();
79  // This function is now broken until an AddBCC call
80 }
81 
83 {
84  return SGetLine(pOrgScript ? pOrgScript->GetScript() : Script, PosForCode[bcc - &Code[0]]);
85 }
86 
88 {
89  assert(!Code.empty());
90  return &Code[0];
91 }
92 
93 C4Value C4AulScriptFunc::Exec(C4PropList * p, C4Value pPars[], bool fPassErrors)
94 {
95  return AulExec.Exec(this, p, pPars, fPassErrors);
96 }
std::vector< const char * > PosForCode
C4AulScriptFunc(C4PropListStatic *Parent, C4ScriptHost *pOrgScript, const char *pName, const char *Script)
C4Value Exec(C4AulScriptFunc *pSFunc, C4PropList *p, C4Value pPars[], bool fPassErrors)
void IncRef()
Definition: C4StringTable.h:27
int SGetLine(const char *szText, const char *cpPosition)
Definition: Standard.cpp:450
C4AulBCCType
C4V_Type ParType[C4AUL_MAX_Par]
std::vector< C4AulBCC > Code
C4ScriptHost * pOrgScript
C4AulExec AulExec
Definition: C4AulExec.cpp:33
C4AulFunc * OwnerOverloaded
#define C4AUL_MAX_Par
Definition: C4AulFunc.h:26
int GetLineOfCode(C4AulBCC *bcc)
void AddBCC(C4AulBCCType eType, intptr_t=0, const char *SPos=0)
void SetOverloaded(C4AulFunc *)
C4AulBCC * GetCode()
virtual C4Value Exec(C4PropList *p, C4Value pPars[], bool fPassErrors=false)
#define X(sdl, oc)
const char * Script
const char * GetScript() const
Definition: C4ScriptHost.h:52
void DecRef()
Definition: C4StringTable.h:28