Skip to content

Commit

Permalink
dofile / love.filesystem.load fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoulsblade committed Apr 27, 2012
1 parent cf21f4b commit b030aeb
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ var gEnableLove080 = false;
var kProfileReportIfTimeAbove = 1*1000; ///< msec
var kProfileReportIfTimeAbove = 0.1*1000; ///< msec

function lua_precompile (code) {
// >>> love.filesystem.load("test.print.myvar.lua")() <<< -> >>> (love.filesystem.load("test.print.myvar.lua"))() <<<
code = code.replace(/(love.filesystem.load)\(([^\)]*)\)\(\)/g,"($1($2))()");
//~ code = code.replace(/([\w\.]+)\(([^\)]*)\)\(\)/g,"($1($2))()");
return code;
}

_lua_load_orig = lua_load;
// overwrite original lua_load for precompile fixes
lua_load = function (chunk, chunkname) { return _lua_load_orig(lua_precompile(chunk), chunkname); }


/// output in html, for fatal error messages etc, also users that don't have webdev console open can see them
function MainPrintToHTMLConsole () {
if (gMaxHTMLConsoleLines == 0) return;
Expand Down Expand Up @@ -160,6 +172,9 @@ function LuaBootStrap (G) {

//~ NOTE: replaces parser lib lua_require(G, path);
};
G.str['dofile'] = function (path) {
return RunLuaFromPath(path);
};
}

/// init lua api
Expand Down Expand Up @@ -200,13 +215,16 @@ function showPreCompiledJS (path) {
var luacode = gLastLoadedLuaCode;

// parse&compile to js
var jscode = "function MyPreCompiledJS() {\n" +
lua_parser.parse(luacode) + "\n" +
" return G;\n" +// thanks to deltaflux, for finding the bug that revealed that this line was missing
"};"

// write to textarea
element.value = jscode;
if (luacode != null) {
luacode = lua_precompile(luacode);
var jscode = "function MyPreCompiledJS() {\n" +
lua_parser.parse(luacode) + "\n" +
" return G;\n" +// thanks to deltaflux, for finding the bug that revealed that this line was missing
"};"

// write to textarea
element.value = jscode;
}
//~ MainPrint("showPreCompiledJS: code written");
}

Expand Down

0 comments on commit b030aeb

Please sign in to comment.