2007-04-16

This commit is contained in:
Anonymous Maarten committed 2015-12-03 01:37:37 +01:00
1 parent 78c27f03c8
commit e20673c2cd
120 files changed
+9578 -1036

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
#include "lua_ini_bridge.h"
#include "log.h"
namespace OpenGTA { namespace Script {
#define GLOBAL_TABLE(name) lua_newtable(L); lua_setglobal(L, name)
IniScriptBridge::IniScriptBridge(const std::string & file) :
ScriptParser(file) {
L = lua_open();
luaL_openlibs(L);
}
IniScriptBridge::~IniScriptBridge() {
lua_close(L);
}
void IniScriptBridge::reset() {
lua_settop(L, 0);
GLOBAL_TABLE("commands");
GLOBAL_TABLE("definitions");
lua_gc(L, LUA_GCCOLLECT, 0);
lua_settop(L, 0);
}
void IniScriptBridge::loadLevel(PHYSFS_uint32 level) {
reset();
ScriptParser::loadLevel(level);
}
void IniScriptBridge::acceptCommand(const char* cmd) {
char *skip_idx = strchr(cmd, ' ');
assert(skip_idx);
*skip_idx = 0;
int idx = atoi(cmd);
++skip_idx;
//INFO << idx << " " << skip_idx << std::endl;
lua_settop(L, 0);
lua_getglobal(L, "commands");
lua_pushinteger(L, idx);
lua_pushstring(L, skip_idx);
lua_settable(L, -3);
lua_settop(L, 0);
}
void IniScriptBridge::acceptDefinition(const char* def) {
char *skip_idx = strchr(def, ' ');
assert(skip_idx);
*skip_idx = 0;
int idx = atoi(def);
skip_idx++;
if (*skip_idx == '1' && *(skip_idx+1) == ' ')
skip_idx += 2;
//INFO << idx << " " << skip_idx << std::endl;
lua_settop(L, 0);
lua_getglobal(L, "definitions");
lua_pushinteger(L, idx);
lua_pushstring(L, skip_idx);
lua_settable(L, -3);
lua_settop(L, 0);
}
}}
#if 0
void on_exit() {
PHYSFS_deinit();
}
int main(int argc, char* argv[]) {
PHYSFS_init(argv[0]);
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
atexit(on_exit);
OpenGTA::Script::IniScriptBridge p(argv[1]);
p.loadLevel(atoi(argv[2]));
if (luaL_loadfile(p.L, argv[3]) || lua_pcall(p.L, 0, 0, 0))
ERROR << lua_tostring(p.L, -1);
return 0;
}
#endif
+25
View File
@@ -0,0 +1,25 @@
#ifndef LUA_INI_BRIDGE_H
#define LUA_INI_BRIDGE_H
#include <string>
#include "read_ini.h"
#include "lua.hpp"
namespace OpenGTA {
namespace Script {
class IniScriptBridge : public ScriptParser {
public:
IniScriptBridge(const std::string &file);
~IniScriptBridge();
lua_State *L;
void loadLevel(PHYSFS_uint32 level);
protected:
void reset();
void acceptDefinition(const char*);
void acceptCommand(const char*);
};
}
}
#endif
+26
View File
@@ -0,0 +1,26 @@
#include "lua_spritecache.h"
namespace OpenGTA {
namespace Script {
using namespace OpenGL;
int SpriteCache::getScale2x(lua_State *L) {
bool b = SpriteCacheHolder::Instance().getScale2x();
lua_pushboolean(L, b);
return 1;
}
int SpriteCache::setScale2x(lua_State *L) {
bool b = SpriteCacheHolder::Instance().getScale2x();
bool v = lua_toboolean(L, 1);
if (b != v)
SpriteCacheHolder::Instance().setScale2x(v);
return 0;
}
#define method(name) {#name, SpriteCache::name}
const luaL_reg SpriteCache::methods[] = {
method(setScale2x),
method(getScale2x),
{NULL, NULL}
};
}
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef LUA_OGTA_SPRITECACHE_H
#define LUA_OGTA_SPRITECACHE_H
#include "gl_spritecache.h"
#include "lua.hpp"
namespace OpenGTA {
namespace Script {
class SpriteCache {
public:
static int getScale2x(lua_State *L);
static int setScale2x(lua_State *L);
static const luaL_reg methods[];
};
}
}
#endif
+21
View File
@@ -1,6 +1,7 @@
#include <string>
#include "lua_vm.h"
#include "lunar.h"
#include "lua_map.h"
#include "lua_cityview.h"
#include "lua_stackguard.h"
#include "lua_camera.h"
@@ -33,22 +34,42 @@ namespace OpenGTA {
void LuaVM::prepare() {
LGUARD(L);
if (!_registered) {
Lunar<Block>::Register2(L);
Lunar<LMap>::Register2(L);
/*
Lunar<CityView>::Register2(L);
luaL_openlib(L, "camera", Camera::methods, 0);
luaL_openlib(L, "screen", Screen::methods, 0);
luaL_openlib(L, "spritecache", SpriteCache::methods, 0);
*/
}
_registered = true;
}
lua_State* LuaVM::getInternalState() {
return(L);
}
void LuaVM::setMap(OpenGTA::Map & map) {
LGUARD(L);
LMap * mptr = static_cast<LMap*>(&map);
lua_gettable(L, LUA_GLOBALSINDEX);
int scv_ref = Lunar<LMap>::push(L, mptr, false);
lua_pushliteral(L, "map");
lua_pushvalue(L, scv_ref);
lua_settable(L, LUA_GLOBALSINDEX);
}
void LuaVM::setCityView(OpenGTA::CityView & cv) {
LGUARD(L);
/*
CityView *scv = static_cast<CityView*>(&cv);
lua_gettable(L, LUA_GLOBALSINDEX);
int scv_ref = Lunar<CityView>::push(L, scv, false);
lua_pushliteral(L, "city_view");
lua_pushvalue(L, scv_ref);
lua_settable(L, LUA_GLOBALSINDEX);
*/
}
void LuaVM::runString(const char* _str) {
+3 -1
View File
@@ -14,18 +14,20 @@ namespace OpenGTA {
void runString(const char*);
void runFile(const char*);
void callSimpleFunction(const char*);
void prepare();
void setCityView(OpenGTA::CityView &);
void setMap(OpenGTA::Map &);
int getGlobalInt(const char*);
float getGlobalFloat(const char*);
const char* getGlobalString(const char*);
void setGlobalInt(const char*, int);
void setGlobalFloat(const char*, float);
void setGlobalString(const char*, const char*);
lua_State *getInternalState();
protected:
lua_State *L;
private:
bool _registered;
void prepare();
};
typedef Loki::SingletonHolder<LuaVM, Loki::CreateUsingNew, Loki::DefaultLifetime,
Loki::SingleThreaded> LuaVMHolder;