summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/scripting.txt1
-rw-r--r--src/script-squirrel.cpp102
2 files changed, 92 insertions, 11 deletions
diff --git a/docs/scripting.txt b/docs/scripting.txt
index 8786e7a2..a70ab592 100644
--- a/docs/scripting.txt
+++ b/docs/scripting.txt
@@ -34,6 +34,7 @@ Item Scripting:
void use(void) - Called when player uses the item.
Public Variables:
+ string name - Name of item.
int type - Type of item (weapon, armor, usable, etc.)
*Special Properties*
diff --git a/src/script-squirrel.cpp b/src/script-squirrel.cpp
index cb3d7601..901ad9a9 100644
--- a/src/script-squirrel.cpp
+++ b/src/script-squirrel.cpp
@@ -1,6 +1,8 @@
#include "script-squirrel.h"
#include <cstring>
+void registerStdLib(HSQUIRRELVM);
+
/*
* printfunc - Print function for Squirrel
*/
@@ -137,15 +139,6 @@ int testFunc(HSQUIRRELVM v)
return 1;
}
-/*
- * Another test function
- */
-int worldTime(HSQUIRRELVM v)
-{
- sq_pushinteger(v, 10);
- return 1;
-}
-
/******/
ScriptSquirrel::ScriptSquirrel(const std::string &file) :
@@ -160,8 +153,7 @@ ScriptSquirrel::ScriptSquirrel(const std::string &file) :
std::cerr << "Error: ScriptSquirrel: could not execute " <<
scriptName << std::endl;
} else {
- functionRegister(vm, testFunc, "printargs");
- functionRegister(vm, worldTime, "worldtime");
+ registerStdLib(vm);
functionCall(vm, "", NULL);
functionCall(vm, "init", NULL);
@@ -191,3 +183,91 @@ void ScriptSquirrel::message(char *msg)
functionCall(vm, "message", "s", msg);
}
+/******************************/
+/*
+ * Standard Library Functions
+ */
+int getName(HSQUIRRELVM v)
+{
+ sq_pushstring(v, "no name", -1);
+ return 1;
+}
+
+int getX(HSQUIRRELVM v)
+{
+ sq_pushinteger(v, 0);
+ return 1;
+}
+
+int getY(HSQUIRRELVM v)
+{
+ sq_pushinteger(v, 0);
+ return 1;
+}
+
+int getMap(HSQUIRRELVM v)
+{
+ sq_pushstring(v, "map1.map", -1);
+ return 1;
+}
+
+int getLevel(HSQUIRRELVM v)
+{
+ sq_pushinteger(v, 0);
+ return 1;
+}
+
+int getHealth(HSQUIRRELVM v)
+{
+ sq_pushinteger(v, 0);
+ return 1;
+}
+
+int getMaxHealth(HSQUIRRELVM v)
+{
+ sq_pushinteger(v, 0);
+ return 1;
+}
+
+int getAttack(HSQUIRRELVM v)
+{
+ sq_pushinteger(v, 0);
+ return 1;
+}
+
+int getDefense(HSQUIRRELVM v)
+{
+ sq_pushinteger(v, 0);
+ return 1;
+}
+
+int getLuck(HSQUIRRELVM v)
+{
+ sq_pushinteger(v, 0);
+ return 1;
+}
+
+int getVitality(HSQUIRRELVM v)
+{
+ sq_pushinteger(v, 0);
+ return 1;
+}
+
+/*
+ * Register standard functions for game script
+ */
+void registerStdLib(HSQUIRRELVM v)
+{
+ functionRegister(v, getName, "getName");
+ functionRegister(v, getX, "getX");
+ functionRegister(v, getY, "getY");
+ functionRegister(v, getMap, "getMap");
+ functionRegister(v, getLevel, "getLevel");
+ functionRegister(v, getHealth, "getHealth");
+ functionRegister(v, getMaxHealth, "getMaxHealth");
+ functionRegister(v, getAttack, "getAttack");
+ functionRegister(v, getDefense, "getDefense");
+ functionRegister(v, getLuck, "getLuck");
+ functionRegister(v, getVitality, "getVitality");
+}
+