How to use the lupa.LuaSyntaxError function in lupa

To help you get started, we’ve selected a few lupa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scrapinghub / splash / splash / kernel / errors.py View on Github external
def error_repr(e):
    """
    Return repr of an exception, for printing as a cell execution result.
    """
    if isinstance(e, (ScriptError, lupa.LuaSyntaxError, lupa.LuaError)):
        if isinstance(e, ScriptError):
            info = e.args[0]
            tp = info['type']
        else:
            info = parse_error_message(e.args[0])
            tp = ScriptError.SYNTAX_ERROR
        line_num = info.get('line_number', -1)
        message = info.get('error', info.get('message'))
        return "%s [input]:%s: %s" % (tp, line_num, message)
    elif isinstance(e, Exception):
        return repr(e)
    return ScriptError.UNKNOWN_ERROR
github scrapinghub / splash / splash / qtrender_lua.py View on Github external
sandboxed=sandboxed,
            lua_package_path=lua_package_path,
            lua_sandbox_allowed_modules=lua_sandbox_allowed_modules
        )
        self.splash = Splash(self.lua, self.tab, self.render_options)

        self.runner = SplashScriptRunner(
            lua=self.lua,
            splash=self.splash,
            log=self.log,
            sandboxed=sandboxed,
        )

        try:
            main_coro = self.get_main(lua_source)
        except (ValueError, lupa.LuaSyntaxError, lupa.LuaError) as e:
            raise ScriptError("lua_source: " + repr(e))

        self.runner.start(
            main_coro=main_coro,
            return_result=self.return_result,
            return_error=self.return_error,
        )
github scrapinghub / splash / splash / kernel / kernel.py View on Github external
try:
            try:
                # XXX: this ugly formatting is important for exception
                # line numbers to be displayed properly!
                lua_source = 'local repr = require("repr"); function main(splash) return repr(%s) end' % code
                main_coro = self._get_main(lua_source)
            except lupa.LuaSyntaxError:
                try:
                    lines = code.splitlines(False)
                    lua_source = '''local repr = require("repr"); function main(splash) %s
                        return repr(%s)
                    end
                    ''' % ("\n".join(lines[:-1]), lines[-1])
                    main_coro = self._get_main(lua_source)
                except lupa.LuaSyntaxError:
                    lua_source = "function main(splash) %s end" % code
                    main_coro = self._get_main(lua_source)

        except (lupa.LuaSyntaxError, lupa.LuaError) as e:
            d = defer.Deferred()
            d.addCallbacks(success, error)
            d.errback(e)
            return d
        except Exception:
            d = defer.Deferred()
            d.addCallbacks(success, error)
            d.errback()
            return d

        d = self.runner.run(main_coro)
        d.addCallbacks(success, error)

lupa

Python wrapper around Lua and LuaJIT

MIT
Latest version published 5 months ago

Package Health Score

80 / 100
Full package analysis

Similar packages