Example #1
0
int luaL_ref(LuaThread* L) {

  LuaTable* registry = L->l_G->getRegistry();

  LuaValue val = L->stack_.top_[-1];
  L->stack_.pop();

  if(val.isNil()) return LUA_REFNIL;

  LuaValue ref1 = registry->get(LuaValue(freelist));
  int ref = ref1.isInteger() ? ref1.getInteger() : 0;

  if (ref != 0) {  // any free element?
    LuaValue temp = registry->get( LuaValue(ref) );
    registry->set( LuaValue(freelist), temp );
    registry->set( LuaValue(ref), val );
    return ref;
  }
  else  {
    // no free elements, get a new reference.
    ref = (int)registry->getLength() + 1;
    registry->set( LuaValue(ref), val );
    return ref;
  }
}
Example #2
0
	void ScriptProp::initEnumItems()
	{
		LuaTable enumTable(-1);
		enumTable.beginRead();
		for (int i = 0; i < enumTable.getLength(); i++) {
			LuaTable enumItem = enumTable.get(i);
			enumItem.beginRead();
			if (enumItem.getLength() >= 2) {
				String key = enumItem.get(0).toString();
				int val = enumItem.get(1).toInt();
				m_enumItems.push_back(std::make_pair(key, val));
			}
			enumItem.endRead();
		}
		enumTable.endRead();
#if 1
		for (lua_pushnil(L); lua_next(L,-2); lua_pop(L, 1)) {
			if (lua_type(L,-2) != LUA_TSTRING)
				continue;

			const char* name = lua_tostring(L, -2);

			if (name[0] == '_') {
				continue;
			}
			
			if (lua_isnumber(L,-1)) {
				m_enumItems.push_back(std::make_pair<String,int>(name, lua_tonumber(L,-1)));
			}
		}
#endif
	}
Example #3
0
LuaValue luaL_getmetatable2(LuaThread* L, const char* tname) {
  LuaTable* registry = L->l_G->getRegistry();

  LuaValue v = registry->get(tname);
  if(v.isNone()) v = LuaValue::Nil();

  return v;
}
Example #4
0
void luaL_unref(LuaThread* L, int ref) {
  THREAD_CHECK(L);

  if(ref >= 0) {
    LuaTable* registry = L->l_G->getRegistry();
    LuaValue a = registry->get( LuaValue(freelist) );
    registry->set( LuaValue(ref), a );
    registry->set( LuaValue(freelist), LuaValue(ref) );
  }
}
Example #5
0
	void GameSound::loadSound( const Variant& v )
	{
		clear();

		if (v.type != Variant::kTable) {
			return;
		}

		LuaTable table = v;

		table.beginRead();
		String name = table.get("sound");
		m_minDist = table.get("minDist");
		m_maxDist = table.get("maxDist");
		m_looping = table.get("looping");
		m_interval = table.get("interval");
		table.endRead();

		if (name.empty())
			return;

		m_sfx << g_soundSystem->createSfx(name);
	}