1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix code style from recent commits and add misc. optimizations

This commit is contained in:
kwolekr 2015-07-02 23:14:30 -04:00
parent 0a0378fece
commit 7b171ea2be
9 changed files with 186 additions and 185 deletions

View file

@ -142,7 +142,7 @@ bool ScriptApiBase::loadScript(const std::string &script_path, std::string *erro
if (!ok) {
std::string error_msg = lua_tostring(L, -1);
if (error)
(*error) = error_msg;
*error = error_msg;
errorstream << "========== ERROR FROM LUA ===========" << std::endl
<< "Failed to load and run script from " << std::endl
<< script_path << ":" << std::endl << std::endl
@ -157,8 +157,8 @@ bool ScriptApiBase::loadScript(const std::string &script_path, std::string *erro
void ScriptApiBase::realityCheck()
{
int top = lua_gettop(m_luastack);
if(top >= 30){
dstream<<"Stack is over 30:"<<std::endl;
if (top >= 30) {
dstream << "Stack is over 30:" << std::endl;
stackDump(dstream);
std::string traceback = script_get_backtrace(m_luastack);
throw LuaError("Stack is over 30 (reality check)\n" + traceback);
@ -172,34 +172,29 @@ void ScriptApiBase::scriptError()
void ScriptApiBase::stackDump(std::ostream &o)
{
int i;
int top = lua_gettop(m_luastack);
for (i = 1; i <= top; i++) { /* repeat for each level */
for (int i = 1; i <= top; i++) { /* repeat for each level */
int t = lua_type(m_luastack, i);
switch (t) {
case LUA_TSTRING: /* strings */
o<<"\""<<lua_tostring(m_luastack, i)<<"\"";
o << "\"" << lua_tostring(m_luastack, i) << "\"";
break;
case LUA_TBOOLEAN: /* booleans */
o<<(lua_toboolean(m_luastack, i) ? "true" : "false");
o << (lua_toboolean(m_luastack, i) ? "true" : "false");
break;
case LUA_TNUMBER: /* numbers */ {
char buf[10];
snprintf(buf, 10, "%g", lua_tonumber(m_luastack, i));
o<<buf;
break; }
default: /* other values */
o<<lua_typename(m_luastack, t);
o << buf;
break;
}
default: /* other values */
o << lua_typename(m_luastack, t);
break;
}
o<<" ";
o << " ";
}
o<<std::endl;
o << std::endl;
}
void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
@ -251,7 +246,7 @@ void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj)
void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
ServerActiveObject *cobj)
{
if(cobj == NULL || cobj->getId() == 0){
if (cobj == NULL || cobj->getId() == 0) {
ObjectRef::create(L, cobj);
} else {
objectrefGet(L, cobj->getId());

View file

@ -51,7 +51,8 @@ public:
ScriptApiBase();
virtual ~ScriptApiBase();
bool loadMod(const std::string &script_path, const std::string &mod_name, std::string *error=NULL);
bool loadMod(const std::string &script_path, const std::string &mod_name,
std::string *error=NULL);
bool loadScript(const std::string &script_path, std::string *error=NULL);
/* object */