AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzScript.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CZ_SCRIPT_H_)
00015 #define _CZ_SCRIPT_H_
00016 
00017 #include "CzXoml.h"
00018 #include "CzXomlVariables.h"
00019 
00020 class CzScene;
00021 
00022 /**
00023  @class IzScriptEngine
00024 
00025  @brief Abstract base class that all script engines derive from
00026 
00027  */
00028 
00029 class IzScriptEngine
00030 {
00031 public:
00032     // Proprties
00033 protected:
00034     CzScene*    Scene;                      ///< Scene that contains this script engine
00035 public:
00036     CzScene*    getScene()                      { return Scene; }
00037     // Properties end
00038 
00039 protected:
00040 public:
00041 
00042     IzScriptEngine() : Scene(NULL) {}
00043     virtual ~IzScriptEngine() {}
00044 
00045     virtual int         Init(CzScene* scene) = 0;
00046     virtual void        Release() = 0;
00047     virtual int         LoadScript(const char* script, int script_len, const char* name) = 0;
00048     virtual int         CallFunction(IzXomlResource* object, CzString* function_name, CzString* param1, CzString* param2, CzString* param3) = 0;
00049     virtual CzXomlProperty getVariable(CzString* var_name) = 0;
00050     virtual int         CallFunctionRef(int function_ref, CzString* param1, CzString* param2, CzString* param3, CzString* param4) = 0;
00051     virtual int         CallFunctionRefWithObject(void* object, int function_ref, CzString* param1, CzString* param2, CzString* param3, CzString* param4) = 0;
00052     virtual CzString    getType() = 0;
00053 
00054     // Internal
00055 };
00056 
00057 /**
00058  @struct    CzScriptCallback
00059 
00060  @brief A script callback.
00061 
00062  */
00063 
00064 struct CzScriptCallback
00065 {
00066     bool                    Valid;              ///< Ttue if this callback is still valid
00067     int                     FunctionRef;        ///< Functiom reference (usually an index)
00068     IzScriptEngine* ScriptEngine;               ///< Script engine that contains the callback
00069 
00070     CzScriptCallback() : Valid(false), FunctionRef(-1), ScriptEngine(NULL) {}
00071 };
00072 
00073 /**
00074  @class CzScript
00075 
00076  @brief A script.
00077 
00078  */
00079 
00080 class CzScript : public IzXomlResource
00081 {
00082 public:
00083     enum eScriptType
00084     {
00085         ST_None,  
00086         ST_LUA, 
00087         ST_AngelScript, 
00088         ST_Javascript, 
00089         ST_Python, 
00090     };
00091     // Proprties
00092 protected:
00093     eScriptType             ScriptType;         ///< Script type
00094     char*                   Script;             ///< The actual script
00095     int                     ScriptLength;       ///< Length of script in bytes
00096 public:
00097     void                    setScriptType(eScriptType type)         { ScriptType = type; }
00098     eScriptType             getScriptType() const                   { return ScriptType; }
00099     bool                    setScript(const char* script, int script_len);
00100     const char*             getScript() const                       { return Script; }
00101     int                     getScriptLength() const                 { return ScriptLength; }
00102     // Properties end
00103 
00104 protected:
00105 public:
00106 
00107     CzScript() : IzXomlResource(), ScriptType(ST_None), Script(NULL), ScriptLength(0)   { setClassType("script"); }
00108     virtual ~CzScript()
00109     {
00110         SAFE_DELETE(Script)
00111     }
00112 
00113     int                 Init(const char* script, int script_len, CzScene* scene = NULL);
00114 
00115     // Implementation of IzXomlResource interface
00116     int                 LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00117 
00118     // Internal
00119 };
00120 
00121 /**
00122  @class CzScriptCreator
00123 
00124  @brief Creates an instance of a game script object from XOML.
00125 
00126  */
00127 
00128 class CzScriptCreator : public IzXomlClassCreator
00129 {
00130 public:
00131     CzScriptCreator()
00132     {
00133         setClassName("script");
00134     }
00135     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzScript(); }
00136 };
00137 
00138 
00139 #endif  // _CZ_SCRIPT_H_