oldprint = print – point the print function to oldprint
function print(c, str) – replace with new print (for our characters)
– do checks here & then write to the creature.
c:writeBuffer(str)
end
bool LuaEngine::runLuaCommand( Creature *c, const std::string &after )
{
bool match = false;
if(!c)
return false;
try {
int top = lua_gettop(mLuaVM);
lua_getglobal(mLuaVM, "sandstorm");
lua_getfield(mLuaVM, -1, "runcommand");
if(!lua_isfunction(mLuaVM, -1))
{
lua_pop(mLuaVM,1);
Log::instance().bug(eLOGLOW, "Warning: Lua script function '%s' does not exist", "sandstorm.runcommand");
return false;
}
SandBind::push<Creature*>(mLuaVM, c);
lua_pushstring( mLuaVM, after.c_str() );
if ( lua_pcall( mLuaVM, 2, 1, 0 ) != 0 )
Log::instance().bug(eLOGLOW, "lua: function 'sandstorm.runcommand': (%s) %s", c->getName().c_str(), lua_tostring( mLuaVM, -1 ) );
if ( !lua_isboolean( mLuaVM, -1 ) )
return false;
match = lua_toboolean( mLuaVM, -1 );
lua_pop( mLuaVM, 1 );
} catch (std::exception &e) {
Log::instance().exception(eLOGLOW, e.what());
} catch (…) {
Log::instance().exception(eLOGLOW, "An unknown error has occured from within runLuaCommand!");
}
return match;
}
The problem is either lua_getfield isn't working properly anymore since the 5.2 change, or I've done something horrifically wrong.
The lua-code it is trying to call is:
No syntax errors or problems in the lua code are detected.
I get 'Warning: Lua script function 'runcommand' does not exist ' because it doesn't detect the function. lua_getfield should identify it within the table sandstorm.