Skip to content

Commit

Permalink
Let you run Lua scripts from specific directories...
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jan 20, 2008
1 parent 5645140 commit 0882e54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lua_glue.c
Expand Up @@ -376,13 +376,13 @@ boolean MojoLua_callProcedure(const char *funcname)
} // MojoLua_callProcedure


boolean MojoLua_runFile(const char *name)
boolean MojoLua_runFileFromDir(const char *dir, const char *name)
{
MojoArchive *ar = GBaseArchive; // in case we want to generalize later.
const MojoArchiveEntry *entinfo;
boolean retval = false;
char *clua = format("scripts/%0.luac", name); // compiled filename.
char *ulua = format("scripts/%0.lua", name); // uncompiled filename.
char *clua = format("%0/%1.luac", dir, name); // compiled filename.
char *ulua = format("%0/%1.lua", dir, name); // uncompiled filename.
int rc = 0;
MojoInput *io = NULL;

Expand Down Expand Up @@ -432,6 +432,12 @@ boolean MojoLua_runFile(const char *name)
} // if

return retval;
} // MojoLua_runFileFromDir


boolean MojoLua_runFile(const char *name)
{
return MojoLua_runFileFromDir("scripts", name);
} // MojoLua_runFile


Expand Down
5 changes: 4 additions & 1 deletion lua_glue.h
Expand Up @@ -27,13 +27,16 @@ void MojoLua_deinitLua(void);
boolean MojoLua_initialized(void);

// Run the code in a given Lua file. This is JUST the base filename.
// We will look for it in GBaseArchive in the scripts/ directory, both as
// We will look for it in GBaseArchive in the (dir) directory, both as
// fname.luac and fname.lua. This code chunk will accept no arguments, and
// return no results, but it can change the global state and alter tables,
// etc, so it can have lasting side effects.
// Will return false if the file couldn't be loaded, or true if the chunk
// successfully ran. Will not return if there's a runtime error in the
// chunk, as it will call fatal() instead.
boolean MojoLua_runFileFromDir(const char *dir, const char *name)

// This is shorthand for MojoLua_runFileFromDir("scripts", fname);
boolean MojoLua_runFile(const char *fname);

// Call a function in Lua. This calls MojoSetup.funcname, if it exists and
Expand Down

0 comments on commit 0882e54

Please sign in to comment.