World model is now operational
This commit is contained in:
@@ -1,17 +1,41 @@
|
||||
|
||||
#include "world.hpp"
|
||||
#include "idalloc.hpp"
|
||||
#include <iostream>
|
||||
|
||||
LuaDefineType(World);
|
||||
|
||||
World::~World() {
|
||||
}
|
||||
|
||||
void World::init(lua_State *L) {
|
||||
World::World() {
|
||||
// Create the lua state.
|
||||
lua_state_ = lua_open();
|
||||
if (lua_state_ == nullptr) {
|
||||
std::cerr << "Cannot create lua state." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Initialize the userdata metatables.
|
||||
LuaStack::register_all_userdata(lua_state_);
|
||||
|
||||
// Prepare to manipulate the lua state.
|
||||
LuaVar world;
|
||||
LuaStack LS(L, world);
|
||||
LS.newpointer(world, new World, false);
|
||||
LuaStack LS(lua_state_, world);
|
||||
|
||||
// Put the world pointer into the lua registry.
|
||||
LS.newpointer(world, this, false);
|
||||
LS.setfield(LuaRegistry, "world", world);
|
||||
|
||||
// Initialize the SourceDB
|
||||
source_db_.initialize(lua_state_);
|
||||
|
||||
// Do an initial lua source update and then environment rebuild.
|
||||
source_db_.update();
|
||||
source_db_.rebuild();
|
||||
|
||||
// Run unit tests.
|
||||
source_db_.run_unittests();
|
||||
}
|
||||
|
||||
World *World::fetch(lua_State *L) {
|
||||
@@ -23,23 +47,3 @@ World *World::fetch(lua_State *L) {
|
||||
return w;
|
||||
}
|
||||
|
||||
LuaDefine(world_init, "c") {
|
||||
World::init(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LuaDefine(world_setid, "c") {
|
||||
LuaArg id;
|
||||
LuaStack LS(L, id);
|
||||
World *w = World::fetch(L);
|
||||
w->id_ = LS.ckinteger(id);
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
LuaDefine(world_getid, "c") {
|
||||
LuaRet id;
|
||||
LuaStack LS(L, id);
|
||||
World *w = World::fetch(L);
|
||||
LS.set(id, w->id_);
|
||||
return LS.result();
|
||||
};
|
||||
Reference in New Issue
Block a user