OpenTTD
script_info.hpp
Go to the documentation of this file.
1 /* $Id: script_info.hpp 26057 2013-11-23 13:12:19Z rubidium $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD 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.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #ifndef SCRIPT_INFO_HPP
13 #define SCRIPT_INFO_HPP
14 
15 #include <squirrel.h>
16 #include "../misc/countedptr.hpp"
17 
18 #include "script_config.hpp"
19 
21 static const int MAX_SL_OPS = 100000;
23 static const int MAX_CONSTRUCTOR_OPS = 100000;
25 static const int MAX_CREATEINSTANCE_OPS = 100000;
27 static const int MAX_GET_OPS = 1000;
29 static const int MAX_GET_SETTING_OPS = 100000;
30 
33 public:
34  ScriptInfo() :
35  engine(NULL),
36  SQ_instance(NULL),
37  main_script(NULL),
38  tar_file(NULL),
39  author(NULL),
40  name(NULL),
41  short_name(NULL),
42  description(NULL),
43  date(NULL),
44  instance_name(NULL),
45  version(0),
46  url(NULL),
47  scanner(NULL)
48  {}
49  ~ScriptInfo();
50 
54  const char *GetAuthor() const { return this->author; }
55 
59  const char *GetName() const { return this->name; }
60 
64  const char *GetShortName() const { return this->short_name; }
65 
69  const char *GetDescription() const { return this->description; }
70 
74  int GetVersion() const { return this->version; }
75 
79  const char *GetDate() const { return this->date; }
80 
84  const char *GetInstanceName() const { return this->instance_name; }
85 
89  const char *GetURL() const { return this->url; }
90 
94  const char *GetMainScript() const { return this->main_script; }
95 
99  const char *GetTarFile() const { return this->tar_file; }
100 
104  bool CheckMethod(const char *name) const;
105 
109  static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info);
110 
114  virtual class ScriptScanner *GetScanner() { return this->scanner; }
115 
119  bool GetSettings();
120 
124  const ScriptConfigItemList *GetConfigList() const;
125 
129  const ScriptConfigItem *GetConfigItem(const char *name) const;
130 
134  SQInteger AddSetting(HSQUIRRELVM vm);
135 
139  SQInteger AddLabels(HSQUIRRELVM vm);
140 
144  int GetSettingDefaultValue(const char *name) const;
145 
149  virtual bool IsDeveloperOnly() const { return false; }
150 
151 protected:
152  class Squirrel *engine;
153  HSQOBJECT *SQ_instance;
155 
156 private:
157  char *main_script;
158  char *tar_file;
159  const char *author;
160  const char *name;
161  const char *short_name;
162  const char *description;
163  const char *date;
164  const char *instance_name;
165  int version;
166  const char *url;
167 
169 };
170 
171 #endif /* SCRIPT_INFO_HPP */
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:74
int version
Version of the script.
class ScriptScanner * scanner
ScriptScanner object that was used to scan this script info.
HSQOBJECT * SQ_instance
The Squirrel instance created for this info.
bool CheckMethod(const char *name) const
Check if a given method exists.
Definition: script_info.cpp:49
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
const char * GetName() const
Get the Name of the script.
Definition: script_info.hpp:59
const char * date
The date the script was written at.
std::list< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
const char * url
URL of the script.
const char * GetShortName() const
Get the 4 character long short name of the script.
Definition: script_info.hpp:64
ScriptConfigItemList config_list
List of settings from this Script.
const char * instance_name
Name of the main class in the script.
int GetSettingDefaultValue(const char *name) const
Get the default value for a setting.
Scanner to help finding scripts.
const char * GetMainScript() const
Get the filename of the main.nut script.
Definition: script_info.hpp:94
const char * GetDate() const
Get the last-modified date of the script.
Definition: script_info.hpp:79
const char * short_name
Short name (4 chars) which uniquely identifies the script.
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
All static information from an Script like name, version, etc.
Definition: script_info.hpp:32
const char * author
Author of the script.
bool GetSettings()
Get the settings of the Script.
const char * GetURL() const
Get the website for this script.
Definition: script_info.hpp:89
Simple counted object.
Definition: countedptr.hpp:206
const ScriptConfigItem * GetConfigItem(const char *name) const
Get the description of a certain Script config option.
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.
const char * GetDescription() const
Get the description of the script.
Definition: script_info.hpp:69
const char * name
Full name of the script.
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
ScriptConfig stores the configuration settings of every Script.
Info about a single Script setting.
static const int MAX_SL_OPS
The maximum number of operations for saving or loading the data of a script.
Definition: script_info.hpp:21
static const int MAX_GET_OPS
Number of operations to get the author and similar information.
Definition: script_info.hpp:27
char * main_script
The full path of the script.
static const int MAX_CREATEINSTANCE_OPS
Number of operations to create an instance of a script.
Definition: script_info.hpp:25
const char * GetAuthor() const
Get the Author of the script.
Definition: script_info.hpp:54
class Squirrel * engine
Engine used to register for Squirrel.
static const int MAX_CONSTRUCTOR_OPS
The maximum number of operations for initial start of a script.
Definition: script_info.hpp:23
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
Definition: script_info.cpp:60
const char * description
Small description of the script.
char * tar_file
If, which tar file the script was in.
static const int MAX_GET_SETTING_OPS
Maximum number of operations allowed for getting a particular setting.
Definition: script_info.hpp:29
const char * GetInstanceName() const
Get the name of the instance of the script to create.
Definition: script_info.hpp:84
const char * GetTarFile() const
Get the filename of the tar the script is in.
Definition: script_info.hpp:99
virtual bool IsDeveloperOnly() const
Can this script be selected by developers only?