Some celx module fixes & improvements.
parent
e51b08f367
commit
a2dba1e519
|
@ -1869,6 +1869,18 @@ const char* CelxLua::safeGetString(int index,
|
|||
return Celx_SafeGetString(m_lua, index, fatalErrors, errorMessage);
|
||||
}
|
||||
|
||||
const char *CelxLua::safeGetNonEmptyString(int index,
|
||||
FatalErrors fatalErrors,
|
||||
const char *errorMessage)
|
||||
{
|
||||
const char *s = safeGetString(index, fatalErrors, errorMessage);
|
||||
if (s == nullptr || *s == '\0')
|
||||
{
|
||||
doError(errorMessage);
|
||||
return nullptr;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
bool CelxLua::safeGetBoolean(int index,
|
||||
FatalErrors fatalErrors,
|
||||
|
|
|
@ -2475,22 +2475,12 @@ static int celestia_getrootcategories(lua_State *l)
|
|||
return celx.pushIterable<UserCategory*>(set);
|
||||
}
|
||||
|
||||
static int celestia_bindtextdomain(lua_State *l)
|
||||
static int celestia_bindtranslationdomain(lua_State *l)
|
||||
{
|
||||
CelxLua celx(l);
|
||||
|
||||
const char *domain = celx.safeGetString(2, AllErrors, "First argument of celestia:bindtranslationdomain must be domain name string.");
|
||||
if (domain == nullptr || *dir == '\0')
|
||||
{
|
||||
celx.doError("Domain name string must not be empty.");
|
||||
return 0;
|
||||
}
|
||||
const char *domain = celx.safeGetNonEmptyString(2, AllErrors, "First argument of celestia:bindtranslationdomain must be domain name string.");
|
||||
const char *dir = celx.safeGetString(3, AllErrors, "Second argument of celestia:bindtranslationdomain must be directory name string.");
|
||||
if (dir == nullptr || *dir == '\0')
|
||||
{
|
||||
celx.doError("Directory name srting must not be empty.");
|
||||
return 0;
|
||||
}
|
||||
const char *newdir = bindtextdomain(domain, dir);
|
||||
if (newdir == nullptr)
|
||||
return 0;
|
||||
|
@ -2519,6 +2509,6 @@ void ExtendCelestiaMetaTable(lua_State* l)
|
|||
celx.registerMethod("deletecategory", celestia_deletecategory);
|
||||
celx.registerMethod("getcategories", celestia_getcategories);
|
||||
celx.registerMethod("getrootcategories", celestia_getrootcategories);
|
||||
celx.registerMethod("bindtranslationdomain", celestia_bindtextdomain);
|
||||
celx.registerMethod("bindtranslationdomain", celestia_bindtranslationdomain);
|
||||
celx.pop(1);
|
||||
}
|
||||
|
|
|
@ -110,11 +110,13 @@ public:
|
|||
lua_pushboolean(m_lua, a);
|
||||
return 1;
|
||||
}
|
||||
#if LUA_VER >= 0x050300
|
||||
int push(int a)
|
||||
{
|
||||
lua_pushinteger(m_lua, a);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
int push(double a)
|
||||
{
|
||||
lua_pushvalue(m_lua, a);
|
||||
|
@ -139,7 +141,7 @@ public:
|
|||
{
|
||||
T *p = newUserData<T>();
|
||||
if (p != nullptr)
|
||||
*p = a;
|
||||
new (p) T(a);
|
||||
return p;
|
||||
}
|
||||
template <typename T> T *newUserDataArray(int n)
|
||||
|
@ -206,7 +208,9 @@ public:
|
|||
/**** type check methods ****/
|
||||
|
||||
bool isType(int index, int type) const;
|
||||
#if LUA_VER >= 0x050300
|
||||
bool isInteger(int n = 0) const { return lua_isinteger(m_lua, n); }
|
||||
#endif
|
||||
bool isNumber(int n = 0) const { return lua_isnumber(m_lua, n); }
|
||||
bool isBoolean(int n = 0) const { return lua_isboolean(m_lua, n); }
|
||||
bool isString(int n = 0) const { return lua_isstring(m_lua, n); }
|
||||
|
@ -215,7 +219,9 @@ public:
|
|||
|
||||
/**** get methods ****/
|
||||
|
||||
#if LUA_VER >= 0x050300
|
||||
int getInt(int n = 0) const { return lua_tointeger(m_lua, n); }
|
||||
#endif
|
||||
double getNumber(int n = 0) const { return lua_tonumber(m_lua, n); }
|
||||
bool getBoolean(int n = 0) const { return lua_toboolean(m_lua, n); }
|
||||
const char *getString(int n = 0) const { return lua_tostring(m_lua, n); }
|
||||
|
@ -288,6 +294,9 @@ public:
|
|||
const char* safeGetString(int index,
|
||||
FatalErrors fatalErrors = AllErrors,
|
||||
const char* errorMessage = "String argument expected");
|
||||
const char *safeGetNonEmptyString(int index,
|
||||
FatalErrors fatalErrors = AllErrors,
|
||||
const char *errorMessage = "Non empty string argument expected");
|
||||
bool safeGetBoolean(int index,
|
||||
FatalErrors fatalErrors = AllErrors,
|
||||
const char* errorMessage = "Boolean argument expected",
|
||||
|
|
Loading…
Reference in New Issue