diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-09 17:52:59 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-09 17:52:59 +0000 |
commit | 015d9180fb6e9024229dfeded26cf9c3553e36d8 (patch) | |
tree | d2cbe3b0414f16f55b43cc48ee11670af61f1459 /src/scripting | |
parent | ac89d3ab1425f973c6d29cbe9856873489eec69b (diff) | |
download | manaserv-015d9180fb6e9024229dfeded26cf9c3553e36d8.tar.gz manaserv-015d9180fb6e9024229dfeded26cf9c3553e36d8.tar.xz manaserv-015d9180fb6e9024229dfeded26cf9c3553e36d8.zip |
Converted NPC class to scripting engine.
Diffstat (limited to 'src/scripting')
-rw-r--r-- | src/scripting/lua.cpp | 17 | ||||
-rw-r--r-- | src/scripting/script.hpp | 12 |
2 files changed, 17 insertions, 12 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index b22d287..099e326 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -47,7 +47,7 @@ class LuaScript: public Script void push(int); - void push(Character *); + void push(Thing *); int execute(); @@ -90,8 +90,11 @@ void LuaScript::push(int v) ++nbArgs; } -void LuaScript::push(Character *v) +void LuaScript::push(Thing *v) { + assert(nbArgs >= 0); + lua_pushlightuserdata(mState, v); + ++nbArgs; } int LuaScript::execute() @@ -99,13 +102,15 @@ int LuaScript::execute() assert(nbArgs >= 0); int res = lua_pcall(mState, nbArgs, 1, 0); nbArgs = -1; - if (res || !lua_isnumber(mState, 0)) + if (res || !lua_isnumber(mState, 1)) { - LOG_ERROR("Failure while calling Lua function: " - << lua_tostring(mState, 0)); + LOG_WARN("Failure while calling Lua function: error=" << res + << ", type=" << lua_typename(mState, lua_type(mState, 1)) + << ", message=" << lua_tostring(mState, 1)); + lua_pop(mState, 1); return 0; } - res = lua_tointeger(mState, 0); + res = lua_tointeger(mState, 1); lua_pop(mState, 1); return res; } diff --git a/src/scripting/script.hpp b/src/scripting/script.hpp index c167dda..5862e50 100644 --- a/src/scripting/script.hpp +++ b/src/scripting/script.hpp @@ -26,7 +26,7 @@ #include <string> -class Character; +class Thing; /** * Abstract interface for calling functions written in an external language. @@ -67,12 +67,12 @@ class Script virtual void push(int) = 0; /** - * Pushes a pointer to Character for the function being prepared. - * It usually is the character doing the action. The interface can - * pass the pointer as an opaque value to the scripting engine, if - * needed. + * Pushes a pointer argument to a game entity. + * The interface can pass the pointer as an opaque value to the + * scripting engine, if needed. This value will usually be passed + * by the script to some callabck functions. */ - virtual void push(Character *) = 0; + virtual void push(Thing *) = 0; /** * Executes the function being prepared. |