Пример #1
0
def main():
    with open('./test/exception.luac', 'rb') as f:
        data = f.read()
        ls = LuaState()
        ls.register('print', py_print)
        ls.register('error', error)
        ls.register('pcall', pcall)
        ls.load(data)
        ls.call(0, 0)
Пример #2
0
def main():
    with open(sys.argv[1], 'rb') as f:
        data = f.read()
        ls = LuaState()
        ls.register('print', py_print)
        ls.register('error', error)
        ls.register('pcall', pcall)
        ls.load(data)
        ls.call(0, 0)
def main():
    with open('./test/vector.luac', 'rb') as f:
        data = f.read()
        ls = LuaState()
        ls.register('print', py_print)
        ls.register('getmetatable', get_metatable)
        ls.register('setmetatable', set_metatable)
        ls.load(data)
        ls.call(0, 0)
Пример #4
0
def main():
    with open(sys.argv[1], 'rb') as f:
        data = f.read()
        ls = LuaState()
        ls.register('print', py_print)
        ls.register('getmetatable', get_metatable)
        ls.register('setmetatable', set_metatable)
        ls.load(data)
        ls.call(0, 0)
Пример #5
0
def main():
    with open('./test/py_function_call.luac', 'rb') as f:
        data = f.read()
        ls = LuaState()
        ls.register('print', py_print)
        ls.load(data)
        ls.call(0, 0)
def main():
    with open('./test/closure_upvalue.luac', 'rb') as f:
        data = f.read()
        ls = LuaState()
        ls.register('print', py_print)
        ls.load(data)
        ls.call(0, 0)
Пример #7
0
def lua_main(proto):
    vm = LuaState(proto)
    vm.set_top(proto.get_max_stack_size())
    while True:
        pc = vm.get_pc()
        i = vm.fetch()
        inst = Instruction(i)
        if inst.op_code() != OpCode.RETURN:
            inst.execute(vm)
            print('[%02d] %-8s ' % (pc + 1, inst.op_name()), end='')
            vm.print_stack()
        else:
            break
Пример #8
0
def main():
    with open(sys.argv[1], 'rb') as f:
        data = f.read()
        ls = LuaState()
        ls.load(data)
        ls.call(0, 0)
Пример #9
0
def main():
    ls = LuaState(None)

    ls.push_boolean(True)
    ls.print_stack()
    ls.push_integer(10)
    ls.print_stack()
    ls.push_nil()
    ls.print_stack()
    ls.push_string('hello')
    ls.print_stack()
    ls.push_value(-4)
    ls.print_stack()
    ls.replace(3)
    ls.print_stack()
    ls.set_top(6)
    ls.print_stack()
    ls.remove(-3)
    ls.print_stack()
    ls.set_top(-5)
    ls.print_stack()
Пример #10
0
def main():
    ls = LuaState()
    ls.register('print', py_print)
    ls.register('getmetatable', get_metatable)
    ls.register('setmetatable', set_metatable)
    ls.register('next', lua_next)
    ls.register('pairs', pairs)
    ls.register('ipairs', ipairs)
    ls.register('error', error)
    ls.register('pcall', pcall)

    ls.load(sys.argv[1])
    ls.call(0, 0)
Пример #11
0
def main():
    with open('./test/function_call.luac', 'rb') as f:
        data = f.read()
        ls = LuaState()
        ls.load(data)
        ls.call(0, 0)
Пример #12
0
def main():
    with open('./test/iterator.luac', 'rb') as f:
        data = f.read()
        ls = LuaState()
        ls.register('print', py_print)
        ls.register('getmetatable', get_metatable)
        ls.register('setmetatable', set_metatable)
        ls.register('next', lua_next)
        ls.register('pairs', pairs)
        ls.register('ipairs', ipairs)
        ls.load(data)
        ls.call(0, 0)
Пример #13
0
def main():
    ls = LuaState(None)

    ls.push_integer(1)
    ls.push_string('2.0')
    ls.push_string('3.0')
    ls.push_number(4.0)
    ls.print_stack()

    ls.arith(ArithOp.ADD)
    ls.print_stack()
    ls.arith(ArithOp.BNOT)
    ls.print_stack()

    ls.len(2)
    ls.print_stack()
    ls.concat(3)
    ls.print_stack()
    ls.push_boolean(ls.compare(1, CmpOp.EQ, 2))
    ls.print_stack()

    ls.push_number(2)
    ls.push_number(2)
    ls.print_stack()
    ls.arith(ArithOp.POW)
    ls.print_stack()

    ls.push_number(3.0)
    ls.push_boolean(ls.compare(4, CmpOp.LT, 5))
    ls.print_stack()

    ls.push_string('hello')
    ls.push_string('world')
    ls.push_boolean(ls.compare(7, CmpOp.LE, 8))
    ls.print_stack()