libs/web: add assert() statements for unresolvable function case
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 30 Nov 2011 12:50:32 +0000 (12:50 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 30 Nov 2011 12:50:32 +0000 (12:50 +0000)
libs/web/luasrc/dispatcher.lua

index 911f2f4e9a59e3ae9fe592a3d410ebbb138af039..7c77f2e97a4c85c15154b4cb6757428391e95eb1 100644 (file)
@@ -761,10 +761,18 @@ end
 
 
 local function _call(self, ...)
+       local func = getfenv()[self.name]
+       assert(func ~= nil,
+              'Cannot resolve function "' .. self.name .. '". Is it misspelled or local?')
+
+       assert(type(func) == "function",
+              'The symbol "' .. self.name .. '" does not refer to a function but data ' ..
+              'of type "' .. type(func) .. '".')
+
        if #self.argv > 0 then
-               return getfenv()[self.name](unpack(self.argv), ...)
+               return func(unpack(self.argv), ...)
        else
-               return getfenv()[self.name](...)
+               return func(...)
        end
 end