// TODO Move arguments from constructor to here?
void timer::start(luabind::object& f)
{
  thread = player->create_lua_thread();
#ifndef NDEBUG
  int old_top = lua_gettop(thread);
#endif
  //function.push(thread);
  f.push(f.interpreter());
  lua_xmove(f.interpreter(), thread, 1);
  assert(old_top + 1 == lua_gettop(thread));

  timer_thread = boost::thread(&timer::count_down, this);
}
Beispiel #2
0
static ComponentTypeId
ComponentFactory_registerComponentType(
    ComponentFactory* self,
    const std::string& name,
    luabind::object cls
) {
    lua_State* L = cls.interpreter();
    auto type = luabind::type(cls);
    if (type != LUA_TUSERDATA) {
        std::string typeName(
            lua_typename(L, type)
        );
        throw std::runtime_error("Argument 2 must be class object, but is: " + typeName);
    }
    ComponentTypeId typeId = self->registerComponentType(
        name,
        [cls] (const StorageContainer& storage) {
            luabind::object classTable = cls;
            luabind::object obj = classTable();
            auto component = std::unique_ptr<Component>(
                luabind::object_cast<Component*>(obj, luabind::adopt(luabind::result))
            );
            component->load(storage);
            return component;
        }
    );
    cls["TYPE_ID"] = typeId;
    return typeId;
}
Beispiel #3
0
  luabind::object menu::build(luabind::object setting)
  {
    using namespace luabind;
    lua_State *L = setting.interpreter();
    const char *title = NULL;
    object m;

    if (!setting || luabind::type(setting) != LUA_TTABLE) { return m; }

    iterator i(setting), end;
    if (setting["title"]) { title = object_cast<const char *>(setting["title"]); }
    else if (setting["t"]) { title = object_cast<const char *>(setting["t"]); }
    else if (setting["label"]) { title = object_cast<const char *>(setting["label"]); }
    else if (type(*i) == LUA_TSTRING)
    {
      title = object_cast<const char *>(*i);
      i++;
    }

    m = globals(L)["lev"]["gui"]["menu"](title);
    for (; i != end; i++)
    {
      if (type(*i) == LUA_TTABLE)
      {
        m["append"](m, *i);
      }
    }
    return m;
  }
Beispiel #4
0
void set_voxel_physics_boxes(const luabind::object &node_o,
		const luabind::object &buffer_o, sp_<VoxelRegistry> voxel_reg)
{
	lua_State *L = node_o.interpreter();

	GET_TOLUA_STUFF(node, 1, Node);
	TRY_GET_TOLUA_STUFF(buf, 2, const VectorBuffer);

	log_d(MODULE, "set_voxel_physics_boxes(): node=%p", node);
	log_d(MODULE, "set_voxel_physics_boxes(): buf=%p", buf);

	ss_ data;
	if(buf == nullptr)
		data = lua_tocppstring(L, 2);
	else
		data.assign((const char*)&buf->GetBuffer()[0], buf->GetBuffer().Size());

	lua_getfield(L, LUA_REGISTRYINDEX, "__buildat_app");
	app::App *buildat_app = (app::App*)lua_touserdata(L, -1);
	lua_pop(L, 1);

	up_<SetPhysicsBoxesTask> task(new SetPhysicsBoxesTask(
			node, data, voxel_reg
			));

	auto *thread_pool = buildat_app->get_thread_pool();

	thread_pool->add_task(std::move(task));
}
Beispiel #5
0
void LVL_Npc::lua_setSequence(luabind::object frames)
{
    int ltype = luabind::type(frames);
    if(luabind::type(frames) != LUA_TTABLE)
    {
        luaL_error(frames.interpreter(), "setSequence exptected int-array, got %s", lua_typename(frames.interpreter(), ltype));
        return;
    }
    animator.setSequence(luabind_utils::convArrayTo<int>(frames));
}
Beispiel #6
0
void clear_voxel_geometry(const luabind::object &node_o)
{
	lua_State *L = node_o.interpreter();

	GET_TOLUA_STUFF(node, 1, Node);

	log_d(MODULE, "clear_voxel_geometry(): node=%p", node);

	CustomGeometry *cg = node->GetComponent<CustomGeometry>();
	if(cg)
		node->RemoveComponent(cg);
}
Beispiel #7
0
void clear_voxel_physics_boxes(const luabind::object &node_o)
{
	lua_State *L = node_o.interpreter();

	GET_TOLUA_STUFF(node, 1, Node);

	log_d(MODULE, "clear_voxel_physics_boxes(): node=%p", node);

	RigidBody *body = node->GetComponent<RigidBody>();
	if(body)
		node->RemoveComponent(body);

	PODVector<CollisionShape*> previous_shapes;
	node->GetComponents<CollisionShape>(previous_shapes);
	for(size_t i = 0; i < previous_shapes.Size(); i++)
		node->RemoveComponent(previous_shapes[i]);
}
Beispiel #8
0
bool NPL::NPLHelper::StringToLuaObject(const char* input, int nLen, luabind::object& output, lua_State* pState)
{
	NPLLex lex;
	LexState* ls = lex.SetInput(input, nLen);
	ls->nestlevel = 0;

	try
	{
		NPLParser::next(ls);  /* read first token */

		if (ls->t.token == '{')
		{
			if (pState == 0)
				pState = output.interpreter();
			luabind::object tabGlobal = luabind::globals(pState);
			luabind::object_index_proxy tabProxy = tabGlobal["__tmp"];

			if (DeserializePureDataBlock(ls, tabProxy))
			{
				NPLParser::testnext(ls, ';');
				if (ls->t.token == NPLLex::TK_EOS)
				{
					output = tabProxy;
					// this is not necessary, the next call will overwrite this. 
					// tabGlobal["__tmp"] = luabind::detail::nil_type();
					return true;
				}
			}
		}
	}
	catch (const char* err)
	{
		OUTPUT_LOG("error: %s in NPLHelper::StringToLuaObject()\n", err);
		return false;
	}
	catch (...)
	{
		OUTPUT_LOG("error: unknown error in NPLHelper::StringToLuaObject()\n");
		return false;
	}
	return false;
}
Beispiel #9
0
  luabind::object menubar::build(luabind::object setting)
  {
    using namespace luabind;
    lua_State *L = setting.interpreter();
    object mb;

    if (!setting || type(setting) != LUA_TTABLE) { return mb; }
    mb = globals(L)["lev"]["gui"]["menubar"]();

    for (iterator i(setting), end; i != end; i++)
    {
      object m, name;
      const char *label1 = NULL, *label2 = NULL;

      iterator j(*i);
      if (j == end || type(*j) != LUA_TSTRING) { continue; }
      label1 = object_cast<const char *>(*j++);
      if (j != end && type(*j) == LUA_TSTRING)
      {
        label2 = object_cast<const char *>(*j++);
      }
      if (j != end && type(*j) == LUA_TSTRING) { name = *j++; }
      else if ((*i)["id"]) { name = (*i)["id"]; }
      else if ((*i)["name"]) { name = (*i)["name"]; }
      m = globals(L)["lev"]["gui"]["menu"](label2);
      for (; j != end; j++)
      {
        if (type(*j) == LUA_TTABLE)
        {
          m["append"](m, *j);
        }
      }
      mb["append"](mb, m, label1, name);
    }
    return mb;
  }
Beispiel #10
0
void set_8bit_voxel_geometry(const luabind::object &node_o,
		int w, int h, int d, const luabind::object &buffer_o,
		sp_<VoxelRegistry> voxel_reg, sp_<AtlasRegistry> atlas_reg)
{
	lua_State *L = node_o.interpreter();

	GET_TOLUA_STUFF(node, 1, Node);
	TRY_GET_TOLUA_STUFF(buf, 5, const VectorBuffer);

	log_d(MODULE, "set_8bit_voxel_geometry(): node=%p", node);
	log_d(MODULE, "set_8bit_voxel_geometry(): buf=%p", buf);

	ss_ data;
	if(buf == nullptr)
		data = lua_tocppstring(L, 5);
	else
		data.assign((const char*)&buf->GetBuffer()[0], buf->GetBuffer().Size());

	if((int)data.size() != w * h * d){
		throw Exception(ss_()+"set_8bit_voxel_geometry(): Data size does not match"
				" with dimensions ("+cs(data.size())+" vs. "+cs(w*h*d)+")");
	}

	lua_getfield(L, LUA_REGISTRYINDEX, "__buildat_app");
	app::App *buildat_app = (app::App*)lua_touserdata(L, -1);
	lua_pop(L, 1);
	Context *context = buildat_app->get_scene()->GetContext();

	CustomGeometry *cg = node->GetOrCreateComponent<CustomGeometry>(LOCAL);

	interface::mesh::set_8bit_voxel_geometry(cg, context, w, h, d, data,
			voxel_reg.get(), atlas_reg.get());

	cg->SetOccluder(true);
	cg->SetCastShadows(true);
}
	SynchronizedRunBuffer::SynchronizedRunBuffer(luabind::object const& delegate) :
		_init(false) {
		_state = delegate.interpreter();
	}