Permalink
Browse files

more useful error message for obj:MissingMethod()

  • Loading branch information...
1 parent 30aebc6 commit 8e84a5a5eaf608b809010b33b9c2789441a39bf5 @ghoulsblade ghoulsblade committed Apr 27, 2012
Showing with 9 additions and 5 deletions.
  1. +4 −1 js/lua-parser.js
  2. +5 −4 js/main.js
View
5 js/lua-parser.js
@@ -1283,6 +1283,7 @@ function lua_call(func, args) {
if (typeof func == "function") {
return lua_rawcall(func, args);
} else {
+ if (func == null) throw new Error("attempt to call nil");
var h = func.metatable && func.metatable.str["__call"];
if (h != null) {
return lua_rawcall(h, [func].concat(args));
@@ -1292,7 +1293,9 @@ function lua_call(func, args) {
}
}
function lua_mcall(obj, methodname, args) {
- return lua_call(lua_tableget(obj, methodname), [obj].concat(args));
+ var fun = lua_tableget(obj, methodname);
+ if (fun == null) throw new Error("attempt to call method '"+String(methodname)+"' (a nil value)");
+ return lua_call(fun, [obj].concat(args));
}
function lua_eq(op1, op2) {
if (typeof op1 != typeof op2) {
View
9 js/main.js
@@ -171,7 +171,7 @@ function Love_Web_CreateTable (G) {
/// e.g. if (string.find(love.web.getAgent(),"MSIE")) then ...mp3... else ...ogg... end
t.str['getAgent'] = function (code) { return [navigator.userAgent]; }
t.str['setMaxFPS'] = function (fps) { gFrameWait = (fps && fps > 0)?(1000/fps):1; }
- t.str['showPreCompiledJS'] = function (path) { ShowPreCompiledJS(path); }
+ t.str['showPreCompiledJS'] = function (path) { showPreCompiledJS(path); }
t.str['browserIsFirefox'] = function () { return [gAgent_Firefox]; }
t.str['browserIsChrome'] = function () { return [gAgent_Chrome]; }
@@ -184,14 +184,14 @@ function Love_Web_CreateTable (G) {
}
-function ShowPreCompiledJS (path) {
+function showPreCompiledJS (path) {
var element = document.getElementById('output');
- if (!element) return; // perhaps during startup
+ if (!element) { MainPrint("showPreCompiledJS: output not found"); return; } // perhaps during startup
var areaid = "precompile_out";
element.innerHTML += encodeURI(path)+"<br/>";
element.innerHTML += "<textarea id='"+areaid+"' style='width:80%;height:100px'/>\n";
var element = document.getElementById(areaid);
- if (!element) return; // perhaps during startup
+ if (!element) { MainPrint("showPreCompiledJS: textarea not found"); return; } // perhaps during startup
// load lua
gLastLoadedLuaCode = false;
@@ -207,6 +207,7 @@ function ShowPreCompiledJS (path) {
// write to textarea
element.value = jscode;
+ //~ MainPrint("showPreCompiledJS: code written");
}
// require "shaders" mari0 main.lua... might be shaders/init.lua ? file_exists()

0 comments on commit 8e84a5a

Please sign in to comment.