00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "luautil.hpp"
00023
00024 #include "game-server/character.hpp"
00025 #include "game-server/npc.hpp"
00026
00027 #include "utils/logger.h"
00028
00029
00030 void raiseScriptError(lua_State *s, const char *format, ...)
00031 {
00032 va_list args;
00033 va_start(args, format);
00034 char message[1024];
00035 vsprintf(message, format, args);
00036 va_end( args );
00037
00038 LOG_WARN("Lua script error: "<<message);
00039 luaL_error(s, message);
00040 }
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 NPC *getNPC(lua_State *s, int p)
00051 {
00052 if (!lua_islightuserdata(s, p)) return NULL;
00053 Thing *t = static_cast<Thing *>(lua_touserdata(s, p));
00054 if (t->getType() != OBJECT_NPC) return NULL;
00055 return static_cast<NPC *>(t);
00056 }
00057
00058 Character *getCharacter(lua_State *s, int p)
00059 {
00060 if (!lua_islightuserdata(s, p)) return NULL;
00061 Thing *t = static_cast<Thing *>(lua_touserdata(s, p));
00062 if (t->getType() != OBJECT_CHARACTER) return NULL;
00063 return static_cast<Character *>(t);
00064 }
00065
00066 Being *getBeing(lua_State *s, int p)
00067 {
00068 if (!lua_islightuserdata(s, p)) return NULL;
00069 Thing *t = static_cast<Thing *>(lua_touserdata(s, p));
00070 return static_cast<Being *>(t);
00071 }
00072
00073 void push(lua_State *s, int val)
00074 {
00075 lua_pushinteger(s, val);
00076 }
00077
00078 void push(lua_State *s, const std::string &val)
00079 {
00080 lua_pushstring(s, val.c_str());
00081 }
00082
00083 void push(lua_State *s, Thing* val)
00084 {
00085 lua_pushlightuserdata(s, val);
00086 }
00087
00088 void push(lua_State *s, double val)
00089 {
00090 lua_pushnumber(s, val);
00091 }