--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/squirrel/core.hpp Thu Mar 15 00:01:33 2007 +0000
@@ -0,0 +1,81 @@
+/* $Id$ */
+
+/** @file core.hpp defines the SquirrelCore class */
+
+#ifndef SQUIRREL_CORE_HPP
+#define SQUIRREL_CORE_HPP
+
+class SquirrelCore {
+private:
+ HSQUIRRELVM vm; ///< The VirtualMachine instnace for squirrel
+
+ /**
+ * The internal RunError handler. It looks up the real error and calls RunError with it.
+ */
+ static SQInteger _RunError(HSQUIRRELVM vm);
+
+protected:
+ /**
+ * The CompileError handler.
+ */
+ static void CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column);
+
+ /**
+ * The RunError handler.
+ */
+ static void RunError(HSQUIRRELVM vm, const char *error);
+
+ /**
+ * If a user runs 'print' inside a script, this function gets the params.
+ */
+ static void PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...);
+
+public:
+ SquirrelCore();
+ ~SquirrelCore();
+
+ /**
+ * Load a script.
+ * @param script The full script-name to load.
+ * @return False if loading failed.
+ */
+ bool LoadScript(const char *script);
+
+ /**
+ * Adds a function to the stack. Depending on the current state this means
+ * either a method or a global function.
+ */
+ void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam, const char *params);
+ void AddMethod(const char *method_name, SQFUNCTION proc);
+
+ /**
+ * Adds a class to the global scope. Make sure to call AddClassEnd when you
+ * are done adding methods.
+ */
+ void AddClassBegin(const char *class_name);
+
+ /**
+ * Finishes adding a class to the global scope. If this isn't called, no
+ * class is really created.
+ */
+ void AddClassEnd();
+
+ /**
+ * Call a method of an instance.
+ */
+ void CallMethod(HSQOBJECT instance, const char *method_name);
+
+ /**
+ * Creates a class instance.
+ * @param class_name The name of the class of which we create an instance.
+ * @param real_instance The instance to the real class, if it represents a real class.
+ * @param instance Returning value with the pointer to the instance.
+ * @return False if creating failed.
+ */
+ bool CreateClassInstance(const char *class_name, void *real_instance, HSQOBJECT *instance);
+
+ HSQUIRRELVM GetVM() { return this->vm; }
+ static bool GetInstance(HSQUIRRELVM vm, SQUserPointer *ptr) { if (SQ_FAILED(sq_getinstanceup(vm, 1, ptr, 0))) return false; return true; }
+};
+
+#endif /* SQUIRREL_CORE_HPP */