コード例 #1
0
ファイル: libwrapper.cpp プロジェクト: chrox/sdcv
void Library::SimpleLookup(const string &str, TSearchResultList& res_list)
{	
	glong ind;
	res_list.reserve(ndicts());
	for (gint idict=0; idict<ndicts(); ++idict)
		if (SimpleLookupWord(str.c_str(), ind, idict))
			res_list.push_back(
				TSearchResult(dict_name(idict), 
					      poGetWord(ind, idict),
					      parse_data(poGetWordData(ind, idict))));
	
}
コード例 #2
0
static int tolua_dict_get(lua_State * L)
{
    dict self = (dict)tolua_tousertype(L, 1, 0);
    const char *name = tolua_tostring(L, 2, 0);
    attrib *a = a_find(*self, &at_dict);

    for (; a && a->type == &at_dict; a = a->next) {
        const char *obj_name = dict_name(a);
        if (obj_name && name && strcmp(obj_name, name) == 0) {
            variant val;
            dict_type type;

            dict_get(a, &type, &val);
            switch (type) {
            case TNONE:
                lua_pushnil(L);
                break;
            case TINTEGER:
                lua_pushinteger(L, val.i);
                break;
            case TREAL:
                lua_pushnumber(L, (lua_Number)val.f);
                break;
            case TREGION:
                tolua_pushusertype(L, val.v, TOLUA_CAST "region");
                break;
            case TBUILDING:
                tolua_pushusertype(L, val.v, TOLUA_CAST "building");
                break;
            case TUNIT:
                tolua_pushusertype(L, val.v, TOLUA_CAST "unit");
                break;
            case TSHIP:
                tolua_pushusertype(L, val.v, TOLUA_CAST "ship");
                break;
            case TSTRING:
                tolua_pushstring(L, (const char *)val.v);
                break;
            default:
                assert(!"not implemented");
            }
            return 1;
        }
    }
    lua_pushnil(L);
    return 1;
}
コード例 #3
0
static int tolua_dict_set_number(lua_State * L)
{
    dict self = (dict)tolua_tousertype(L, 1, 0);
    const char *name = tolua_tostring(L, 2, 0);
    lua_Number value = tolua_tonumber(L, 3, 0);
    attrib *a = a_find(*self, &at_dict);
    variant val;

    val.f = (float)value;

    for (; a && a->type == &at_dict; a = a->next) {
        if (strcmp(dict_name(a), name) == 0) {
            dict_set(a, TREAL, val);
            return 0;
        }
    }

    a = a_add(self, dict_create(name, TREAL, val));
    return 0;
}
コード例 #4
0
static int tolua_dict_set_usertype(lua_State * L, int type)
{
    dict self = (dict)tolua_tousertype(L, 1, 0);
    const char *name = tolua_tostring(L, 2, 0);
    unit *value = tolua_tousertype(L, 3, 0);
    attrib *a = a_find(*self, &at_dict);
    variant val;

    val.v = value;

    for (; a && a->type == &at_dict; a = a->next) {
        if (strcmp(dict_name(a), name) == 0) {
            dict_set(a, type, val);
            return 0;
        }
    }

    a = a_add(self, dict_create(name, type, val));
    return 0;
}