diff options
| author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-20 22:46:55 +0100 |
|---|---|---|
| committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-21 07:29:13 +0100 |
| commit | 4559ca444daacfd02ebb05f1657148a2b4cf3d8b (patch) | |
| tree | 8410fe19f397e70d43a8542c6ba7339d61d9bc0e /src/scripting/script.cpp | |
| parent | ad1d58b795681cad74642c0f4818b66a3f869794 (diff) | |
Introduced Script::Context
This should allow to finally call functions to lua without having to care
about working around situations where a lua call causes a c++ call which
needs to call to lua again.
Tested against the source of tales repository data.
Diffstat (limited to 'src/scripting/script.cpp')
| -rw-r--r-- | src/scripting/script.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp index 63ab7ff..72943d4 100644 --- a/src/scripting/script.cpp +++ b/src/scripting/script.cpp @@ -40,7 +40,7 @@ Script::Ref Script::mUpdateCallback; Script::Script(): mCurrentThread(0), - mMap(0) + mContext(0) {} Script::~Script() @@ -95,14 +95,14 @@ static char *skipPotentialBom(char *text) return (strncmp(text, utf8Bom, bomLength) == 0) ? text + bomLength : text; } -bool Script::loadFile(const std::string &name) +bool Script::loadFile(const std::string &name, const Context &context) { int size; char *buffer = ResourceManager::loadFile(name, size); if (buffer) { mScriptFile = name; - load(skipPotentialBom(buffer), name.c_str()); + load(skipPotentialBom(buffer), name.c_str(), context); free(buffer); return true; } else { @@ -114,7 +114,8 @@ void Script::loadNPC(const std::string &name, int id, ManaServ::BeingGender gender, int x, int y, - const char *prog) + const char *prog, + MapComposite *map) { if (!mCreateNpcDelayedCallback.isValid()) { @@ -122,14 +123,23 @@ void Script::loadNPC(const std::string &name, "Could not enabled NPC"); return; } - load(prog, name.c_str()); + Context context; + context.map = map; + load(prog, name.c_str(), context); prepare(mCreateNpcDelayedCallback); push(name); push(id); push(gender); push(x); push(y); - execute(); + execute(context); +} + +int Script::execute(MapComposite *map) +{ + Context context; + context.map = map; + return execute(context); } @@ -153,8 +163,7 @@ static void fastRemoveOne(std::vector<T> &vector, T value) Script::Thread::Thread(Script *script) : mScript(script), - mState(ThreadPending), - mMap(0) + mState(ThreadPending) { script->mThreads.push_back(this); } |
