[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Script load or execution error
- From: David Burgess <dburgess@...>
- Date: Wed, 2 Mar 2005 14:54:04 +1000
What is the message that is returned?
int retcode = lua_pcall(ScriptMgr->GetState(), 1, 1, 0);
if (retcode) {
>> const char* msg = lua_tostring(L, -1);
>> if (!msg) msg ="error with no message";
string error;
error = "ScriptMgr::Execute() -> ";
error += "Error running function main(): ";
>> error += msg;
error += script;
throw ScriptError(error, retcode);
}
Given the message you should be able to source the problem.
On Tue, 1 Mar 2005 21:44:55 -0700, Jason Murdick <wjmurdick@gmail.com> wrote:
> Hello,
>
> I am hoping that someone on this list could give me some suggestions
> with a problem I'm having. I have a singleton in my application that
> contains an Execute() method that will attempt to run the scripts it
> is passed. First, it attempts to load a module named base.lua which
> contains (among others) a function:
>
> function Execute(script)
> local f = loadfile(script)()
> main()
> end
>
> Every script file that is called is wrapped in a simple function call
> "function main()" with no arguments. I'll list the C++ below, but the
> error I keep getting is LUA_ERRRUN and it is not executing the
> function in base.lua.
>
> bool ScriptHandler::Execute(string script)
> {
> try
> {
> // load the indicated module
> string path;
> path = GLOBALS->basepath();
> path += "modules\\base.lua";
> luaL_loadfile (ScriptMgr->GetState(), path.c_str());
>
> // Execute the script
> if (lua_isfunction (ScriptMgr->GetState(), -1))
> lua_pcall (ScriptMgr->GetState(), 0, 1, 0);
>
> // push functions and arguments
> lua_getglobal(ScriptMgr->GetState(), "execute");
> lua_pushstring(ScriptMgr->GetState(), script.c_str());
>
> // do the call (1 arguments, 1 result)
> int retcode = lua_pcall(ScriptMgr->GetState(), 1, 1, 0);
> if (retcode) {
> string error;
> error = "ScriptMgr::Execute() -> ";
> error += "Error running function main(): ";
> error += script;
> throw ScriptError(error, retcode);
> }
> return true;
> }
> catch(ScriptError err)
> {
> err.LogError();
> return false;
> }
> }
>
> My goal is for every single script file in my application to have
> access to the functions in base.lua without having to use "require" or
> "loadlib" or anything of that sort. At the same time, I would like to
> be able to have a single path through which all scripts are executed,
> since some scripts will likely be written by other individuals at a
> later date. Perhaps someone could review the code below and point me
> in the right direction?
>
> Thanks in advance for any pointers you may be able to provide.
>
> Jason Murdick
>