How to use the lupa.LuaRuntime 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 sassoftware / python-swat / swat / utils / testing.py View on Github external
Returns
    -------
    (cashost, casport, casprotocol)

    '''
    cashost = None
    casport = None
    casprotocol = None

    if not os.path.isfile(path):
        return cashost, casport, casprotocol

    try:
        from lupa import LuaRuntime
        lua = LuaRuntime()
        lua.eval('dofile("%s")' % path)
        lg = lua.globals()

    except ImportError:
        import subprocess
        import tempfile

        lua_script = tempfile.TemporaryFile(mode='w')
        lua_script.write('''
            if arg[1] then
                dofile(arg[1])
                for name, value in pairs(_G) do
                    if name:match('cas') then
                        print(name .. ' ' .. tostring(value))
                    end
                end
github airscript / airscript-engine / runtime / __init__.py View on Github external
import requests

from runtime import base64
from runtime import json
from runtime import http
from runtime import mail

__all__ = """
base64
json
http
mail
""".split()

try:
    lua = lupa.LuaRuntime()
except:
    pass # for local debugging without lupa

def _export_globals():
    d = dict()
    for k in __all__:
        d[k] = globals()[k]
    return d

def make_table(dict):
    return lua.eval("""
function(d)
    local t = {}
    for key, value in python.iterex(d.items()) do
        t[key] = value
    end
github ho4040 / pini-engine / Editor / pini / command / ScriptCommands.py View on Github external
def luaInit(self):
		self.lua = LuaRuntime()
		############ FOR TEST ############
		PROJPATH = ProjectController().path.replace(QDir.separator(),"/")
		BUILDPATH = PROJPATH + u"/build/?.lua;"
		BUILDPATH1 = PROJPATH + u"/build/scene/?.lua;"
		BUILDPATH2 = PROJPATH + u"/build/module/?.lua;"

		BUILDPATH = BUILDPATH.encode(os_encoding.cp())
		BUILDPATH1 = BUILDPATH1.encode(os_encoding.cp())
		BUILDPATH2 = BUILDPATH2.encode(os_encoding.cp())
		
		self.lua.execute("package.path = \"\"")
		self.lua.execute("function packagePath(path) package.path = package.path .. ';'..path end")		
		self.lua.globals().packagePath(BUILDPATH)
		self.lua.globals().packagePath(BUILDPATH1)
		self.lua.globals().packagePath(BUILDPATH2)
github AcidWeb / CurseBreaker / CB / Wago.py View on Github external
def __init__(self):
        self.lua = LuaRuntime()
        self.urlParser = re.compile('/([a-zA-Z0-9_-]+)/(\d+)')
        self.list = {}
        self.ignored = {}
        self.uids = {}
        self.ids = {}
        self.data = {'slugs': [], 'uids': [], 'ids': []}
github strfry / OpenNFB / launcher.py View on Github external
def load_protocol(self, path):
		lua = lupa.LuaRuntime(attribute_handlers=(getter, setter))
		self.lua = lua
		lua.globals()["flow"] = flow
		lua.globals()["channels"] = self.context.get_channels()
		lua.globals()["context"] = self.context
		source = open(path).read()

		try:
			lua.execute(source)
			self.guiBlocks = lua.eval('setup()')
			#lua.eval('gui()')
		except Exception as e:
			print ('Lua Exception occured: ', e, type(e))
			raise

		for block in self.guiBlocks:
			dock = Dock(block.name)
github jamesls / fakeredis / fakeredis_old.py View on Github external
isinstance(numkeys, t) for t in (text_type, str, bytes)
        ):
            try:
                numkeys = int(numkeys)
            except ValueError:
                # Non-numeric string will be handled below.
                pass
        if not isinstance(numkeys, int_types):
            raise ResponseError("value is not an integer or out of range")
        elif numkeys > len(keys_and_args):
            raise ResponseError("Number of keys can't be greater than number of args")
        elif numkeys < 0:
            raise ResponseError("Number of keys can't be negative")

        keys_and_args = [to_bytes(v) for v in keys_and_args]
        lua_runtime = LuaRuntime(unpack_returned_tuples=True)

        set_globals = lua_runtime.eval(
            """
            function(keys, argv, redis_call, redis_pcall)
                redis = {}
                redis.call = redis_call
                redis.pcall = redis_pcall
                redis.error_reply = function(msg) return {err=msg} end
                redis.status_reply = function(msg) return {ok=msg} end
                KEYS = keys
                ARGV = argv
            end
            """
        )
        expected_globals = set()
        set_globals(
github scrapinghub / splash / splash / lua.py View on Github external
def is_supported():
    """ Return True if Lua scripting is supported """
    global _supported
    if _supported is not None:
        return _supported

    try:
        import lupa
    except ImportError:
        log.msg("WARNING: Lua scripting is not available because 'lupa' Python package is not installed")
        _supported = False
        return False

    try:
        lua = lupa.LuaRuntime()
    except lupa.LuaError as e:
        log.msg("WARNING: Lua scripting is not available: %r" % e)
        _supported = False
        return False

    _supported = True
    return True
github baojie / pydatalog / pyDatalog / pyDatalog.py View on Github external
def __init__(self):
        self.clauses = []
        self.lua = LuaRuntime()
        
        lua_program_path = os.path.join(os.path.dirname(__file__), 'luaEngine.py')
        lua_program = open(lua_program_path).read()
        self.lua.execute(lua_program)
        
        self._insert = self.lua.eval('table.insert')
        self._make_const = self.lua.eval('datalog.make_const')      # make_const(id) --> { id: } unique, inherits from Const
        self._make_var = self.lua.eval('datalog.make_var')          # make_var(id) --> { id: ) unique, inherits from Var
        self.lua_make_literal = self.lua.eval('datalog.make_literal')  # make_literal(pred_name, terms) --&gt; { pred: , id: , <i>: , tag: } 
                                                                    #    where id represents name, terms; 
                                                                    #    where tag is used as a key to literal by the subgoal table
        self._make_literal = lambda name, atoms: self.lua_make_literal(name, self.lua_table(atoms))
        
        self.lua_make_clause = self.lua.eval('datalog.make_clause')    # make_clause(head, body) = { head: , <i>: }
        self._make_clause = lambda head, body: self.lua_make_clause(head, self.lua_table(body))
        
</i></i>

lupa

Python wrapper around Lua and LuaJIT

MIT
Latest version published 6 months ago

Package Health Score

80 / 100
Full package analysis

Similar packages