📄 oasisscriptsystem.h
字号:
/******************************************************************************
* This source file is part of Bad Camel Gaming
* Copyright (C) 2003 Zephie Greyvenstein
* See Readme.html for acknowledgements
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
/******************************************************************************
* FILENAME : oasisScriptSystem.h
* DESCRIPTION : Scripting engine
* AUTHOR : Zephie Greyvenstein
*****************************************************************************/
/// Avoid double inclusion
#ifndef __SCRIPTSYSTEM_H__
#define __SCRIPTSYSTEM_H__
/// Include common stuff
#include "oasisCommon.h"
/// Include the rest of the needed oasis stuff
#include "oasisResourceManager.h"
#include "oasisSystem.h"
#include "oasisScriptCommon.h"
#include "oasisSingleton.h"
namespace Oasis {
/// Scripting engine, only one language can be active at a time.
class _oasisExport scriptSystem : public system,
public singleton< scriptSystem > {
/// The script system needs access to data functions
friend class scriptInterpreter;
friend class scriptExtension;
public:
/// Language choices are Ruby and Lua for now.
enum Language {
LNONE = 0,
LLUA = 1,
LRUBY = 2
};
/// Constructor
scriptSystem( );
/// Destructor
virtual ~scriptSystem( );
/// Get singleton
static scriptSystem &get( void );
/// Get singleton pointer
static scriptSystem *getPtr( void );
/// Reset this system
void reset( void );
/// Update this system
void update( real time );
/// This will initialize your language of choice.
/// If there is a conflict with a pre-existing langauge,
/// That language will be unloaded.
void initLanguage( Language toinit );
/// Feed the script engine a command string
/// This will actually return a C type (see below)
/// Do we need a function that will call a string and not return a type?
void *executeString( uint8 &type, const char *command, ... );
/// Execute the script given by name.
void executeScript( const string &name );
/** @remarks
Calls the function funct with arguments defined in printf style
types is a string in the form of 'iissidr' and the like, where
each character means 'Im passing in the following datatype'.
'0' - NULL
'b' - bool
's' - char *
'i' - int32
'd' - int16
'f' - real
'r' - real
'v' - vector(3-element array)
'q' - quaternion(4-element array)
'c' - character
returntype is the return information of the function,
coincidentally, it is in the same format as stated above.
You are also responsible for freeing any return value.
Note that the value passed back will be a pointer to type
returntype, this is true for all except (char *) :)
For more information, read the source :) */
void *callFunction(uint8 &returntype, string funct, char * types, ... );
/// Log something via the script engine, which writes out to the console
/// if it exists
static void scriptLog( const string &message );
/// Garbage collection for any given type inside a void *.
void freeVariable( void * var, uint8 type );
/// Convert the inputted type to a relevant string value
/// on undefined types, returns "Undefined"
string toString( void *var, uint8 type );
/// returns the currently loaded script type
inline Language getLanguage( ) {
return loaded;
}
/// returns the currently loaded interpreter
inline scriptInterpreter *getInterpreter( ) {
return specifics;
}
// Add a script extension
// must be done before 'initLanguage'
inline void extend( scriptExtension *ext ) {
extensions.push_back( ext );
}
private:
scriptInterpreter *specifics;
Language loaded;
std::vector < scriptExtension * > extensions;
};
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -