-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest.lua
More file actions
51 lines (45 loc) · 1.08 KB
/
test.lua
File metadata and controls
51 lines (45 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local bytecode = require "luavm.bytecode"
local vm = require "luavm.vm".native()
function pass(...)
return ...
end
local dump = string.dump(function(...)
print(...)
local r,e = 4,4
local a, b, c = pass(1,2,3)
print(a,b,c)
print(unpack({4,6,2,4}))
local function t()
r = 5
e = 6
end
t()
print(r,e)
local i = 1
while true do
local m = math.random(1,100)
print("iter "..i,m)
if m < 15 then
break
end
i = i+1
end
return false and 1 or 0
end)
--print(vm.lua51.run(bytecode.load(dump),{"h","i",3,4,5}))
local testbc = string.dump(function() return "Hello" end)
local testbcl = bytecode.load(testbc)
local testbco = bytecode.save(testbcl)
assert(testbc == testbco,"Bytecode save test failed, INCONSISTENT!")
print(vm.lua51.run(testbcl))
print(loadstring(testbc)())
print(loadstring(testbco)())
loadfile("hello.lua")()
vm.run(bytecode.load(string.dump(loadfile("hello.lua"))))
local opscalled = 0
vm.run(
bytecode.load(string.dump(function() while true do end end)),
nil,
nil,
nil,
function() opscalled = opscalled+1 if opscalled > 480000 then error("Timeout.",0) end end)