summaryrefslogtreecommitdiffstats
path: root/src/script/script.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/script.cpp')
-rw-r--r--src/script/script.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/script/script.cpp b/src/script/script.cpp
index 1f86e71..dc10425 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -155,6 +155,18 @@ CBotTypResult CScript::cString(CBotVar* &var, void* user)
return CBotTypResult(CBotTypFloat);
}
+// Compiling a procedure with a single string, returning string.
+
+CBotTypResult CScript::cStringString(CBotVar* &var, void* user)
+{
+ if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
+ if ( var->GetType() != CBotTypString &&
+ var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
+ var = var->GetNext();
+ if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
+ return CBotTypResult(CBotTypString);
+}
+
// Seeking value in an array of integers.
@@ -499,6 +511,29 @@ bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* us
return true;
}
+
+// Instruction "progfunc(funcname)".
+
+bool CScript::rProgFunc(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ CBotString cbs;
+ const char* funcname;
+ std::string program;
+
+ cbs = var->GetValString();
+ funcname = cbs;
+
+ //TODO: Translation :)
+ program = "extern void object::Auto()\n{\n\t\n\t//Automatically generated by progfunc(\"";
+ program += funcname;
+ program += "\");\n\t";
+ program += funcname;
+ program += "();\n\t\n}\n";
+
+ result->SetValString(program.c_str());
+
+ return true;
+}
// Compilation of instruction "object.busy()"
CBotTypResult CScript::cBusy(CBotVar* thisclass, CBotVar* &var)
{
@@ -3402,6 +3437,7 @@ void CScript::InitFonctions()
CBotProgram::AddFunction("setresearchenable", rSetResearchEnable, CScript::cOneFloat);
CBotProgram::AddFunction("setresearchdone", rSetResearchDone, CScript::cOneFloat);
+ CBotProgram::AddFunction("progfunc", rProgFunc, CScript::cStringString);
CBotProgram::AddFunction("retobject", rGetObject, CScript::cGetObject);
CBotProgram::AddFunction("retobjectbyid", rGetObjectById, CScript::cGetObject);
CBotProgram::AddFunction("delete", rDelete, CScript::cDelete);