diff options
author | truebrain <truebrain@openttd.org> | 2011-12-19 20:56:59 +0000 |
---|---|---|
committer | truebrain <truebrain@openttd.org> | 2011-12-19 20:56:59 +0000 |
commit | 963802e9a7cb67f51cb7e6ffe9d33a02cfe93821 (patch) | |
tree | d8b2d5c1c2d90c7cb1a02403cea942ab52c2e501 /src/game/game_info.cpp | |
parent | 83f2785f54de1c31267c5586464c97fb39f95b5a (diff) | |
download | openttd-963802e9a7cb67f51cb7e6ffe9d33a02cfe93821.tar.xz |
(svn r23612) -Add: allow importing libraries in the same way as AI does, only with GS prefix (and in game/library)
Diffstat (limited to 'src/game/game_info.cpp')
-rw-r--r-- | src/game/game_info.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/game/game_info.cpp b/src/game/game_info.cpp index 722a9fc91..2d304bc94 100644 --- a/src/game/game_info.cpp +++ b/src/game/game_info.cpp @@ -99,3 +99,40 @@ bool GameInfo::CanLoadFromVersion(int version) const if (version == -1) return true; return version >= this->min_loadable_version && version <= this->GetVersion(); } + + +GameLibrary::~GameLibrary() +{ + free(this->category); +} + +/* static */ void GameLibrary::RegisterAPI(Squirrel *engine) +{ + /* Create the GameLibrary class, and add the RegisterLibrary function */ + engine->AddClassBegin("GSLibrary"); + engine->AddClassEnd(); + engine->AddMethod("RegisterLibrary", &GameLibrary::Constructor, 2, "tx"); +} + +/* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm) +{ + /* Create a new library */ + GameLibrary *library = new GameLibrary(); + + SQInteger res = ScriptInfo::Constructor(vm, library); + if (res != 0) { + delete library; + return res; + } + + /* Cache the category */ + if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethodStrdup(*library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) { + delete library; + return SQ_ERROR; + } + + /* Register the Library to the base system */ + library->GetScanner()->RegisterScript(library); + + return 0; +} |