Repository navigation
Expand file tree
/
Copy pathaaaa.lua
More file actions
5606 lines (5103 loc) · 187 KB
/
Copy pathaaaa.lua
File metadata and controls
5606 lines (5103 loc) · 187 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--https://github.com/Mokiros/roblox-FE-compatibility
if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
local Player,game,owner = owner,game
local RealPlayer = Player
do
print("FE Compatibility code V2 by Mokiros")
local RealPlayer = RealPlayer
script.Parent = RealPlayer.Character
--Fake event to make stuff like Mouse.KeyDown work
local Disconnect_Function = function(this)
this[1].Functions[this[2]] = nil
end
local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
local FakeEvent_Metatable = {__index={
Connect = function(this,f)
local i = tostring(math.random(0,10000))
while this.Functions[i] do
i = tostring(math.random(0,10000))
end
this.Functions[i] = f
return setmetatable({this,i},Disconnect_Metatable)
end
}}
FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect
local function fakeEvent()
return setmetatable({Functions={}},FakeEvent_Metatable)
end
--Creating fake input objects with fake variables
local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
FakeMouse.keyUp = FakeMouse.KeyUp
FakeMouse.keyDown = FakeMouse.KeyDown
local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
end}
--Merged 2 functions into one by checking amount of arguments
CAS.UnbindAction = CAS.BindAction
--This function will trigger the events that have been :Connect()'ed
local function TriggerEvent(self,ev,...)
for _,f in pairs(self[ev].Functions) do
f(...)
end
end
FakeMouse.TriggerEvent = TriggerEvent
UIS.TriggerEvent = TriggerEvent
--Client communication
local Event = Instance.new("RemoteEvent")
Event.Name = "UserInput_Event"
Event.OnServerEvent:Connect(function(plr,io)
if plr~=RealPlayer then return end
FakeMouse.Target = io.Target
FakeMouse.Hit = io.Hit
if not io.isMouse then
local b = io.UserInputState == Enum.UserInputState.Begin
if io.UserInputType == Enum.UserInputType.MouseButton1 then
return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up")
end
if io.UserInputType == Enum.UserInputType.MouseButton2 then
return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up")
end
for _,t in pairs(CAS.Actions) do
for _,k in pairs(t.Keys) do
if k==io.KeyCode then
t.Function(t.Name,io.UserInputState,io)
end
end
end
FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false)
end
end)
Event.Parent = NLS([==[local Event = script:WaitForChild("UserInput_Event")
local Mouse = owner:GetMouse()
local UIS = game:GetService("UserInputService")
local input = function(io,RobloxHandled)
if RobloxHandled then return end
--Since InputObject is a client-side instance, we create and pass table instead
Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
end
UIS.InputBegan:Connect(input)
UIS.InputEnded:Connect(input)
local h,t
--Give the server mouse data every second frame, but only if the values changed
--If player is not moving their mouse, client won't fire events
local HB = game:GetService("RunService").Heartbeat
while true do
if h~=Mouse.Hit or t~=Mouse.Target then
h,t=Mouse.Hit,Mouse.Target
Event:FireServer({isMouse=true,Target=t,Hit=h})
end
--Wait 2 frames
for i=1,2 do
HB:Wait()
end
end]==],script)
----Sandboxed game object that allows the usage of client-side methods and services
--Real game object
local RealGame = game
--Metatable for fake service
local FakeService_Metatable = {
__index = function(self,k)
local s = rawget(self,"_RealService")
if s then
return typeof(s[k])=="function"
and function(_,...)return s[k](s,...)end or s[k]
end
end,
__newindex = function(self,k,v)
local s = rawget(self,"_RealService")
if s then s[k]=v end
end
}
local function FakeService(t,RealService)
t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService
return setmetatable(t,FakeService_Metatable)
end
--Fake game object
local FakeGame = {
GetService = function(self,s)
return rawget(self,s) or RealGame:GetService(s)
end,
Players = FakeService({
LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
},"Players"),
UserInputService = FakeService(UIS,"UserInputService"),
ContextActionService = FakeService(CAS,"ContextActionService"),
RunService = FakeService({
_btrs = {},
RenderStepped = RealGame:GetService("RunService").Heartbeat,
BindToRenderStep = function(self,name,_,fun)
self._btrs[name] = self.Heartbeat:Connect(fun)
end,
UnbindFromRenderStep = function(self,name)
self._btrs[name]:Disconnect()
end,
},"RunService")
}
rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer)
FakeGame.service = FakeGame.GetService
FakeService(FakeGame,game)
--Changing owner to fake player object to support owner:GetMouse()
game,owner = FakeGame,FakeGame.Players.LocalPlayer
end
-- this is where local script starts
--Converted with ttyyuu12345's model to script plugin v4
function sandbox(var,func)
local env = getfenv(func)
local newenv = setmetatable({},{
__index = function(self,k)
if k=="script" then
return var
else
return env[k]
end
end,
})
setfenv(func,newenv)
return func
end
cors = {}
mas = Instance.new("Model",game:GetService("Lighting"))
Script0 = Instance.new("Script")
ModuleScript1 = Instance.new("ModuleScript")
ModuleScript2 = Instance.new("ModuleScript")
ModuleScript3 = Instance.new("ModuleScript")
ModuleScript4 = Instance.new("ModuleScript")
ModuleScript5 = Instance.new("ModuleScript")
ModuleScript6 = Instance.new("ModuleScript")
ModuleScript7 = Instance.new("ModuleScript")
ModuleScript8 = Instance.new("ModuleScript")
Script0.Parent = TextButton15
table.insert(cors,sandbox(Script0,function()
local remote = script.Parent.MSFunction
remote.OnServerEvent:Connect(function(idk, lol)
require(script.Loadstring)(lol)()
end)
end))
ModuleScript1.Name = "Loadstring"
ModuleScript1.Parent = Script0
table.insert(cors,sandbox(ModuleScript1,function()
--[[
Credit to einsteinK.
Credit to Stravant for LBI.
Credit to the creators of all the other modules used in this.
Sceleratis was here and decided modify some things.
einsteinK was here again to fix a bug in LBI for if-statements
--]]
local waitDeps = {
'Rerubi';
'LuaK';
'LuaP';
'LuaU';
'LuaX';
'LuaY';
'LuaZ';
}
for i,v in pairs(waitDeps) do script:WaitForChild(v) end
local luaX = require(script.LuaX)
local luaY = require(script.LuaY)
local luaZ = require(script.LuaZ)
local luaU = require(script.LuaU)
local rerubi = require(script.Rerubi)
luaX:init()
local LuaState = {}
getfenv().script = nil
return function(str,env)
local f,writer,buff,name
local env = env or getfenv(2)
local name = (env.script and env.script:GetFullName())
local ran,error = pcall(function()
local zio = luaZ:init(luaZ:make_getS(str), nil)
if not zio then return error() end
local func = luaY:parser(LuaState, zio, nil, name or "nil")
writer, buff = luaU:make_setS()
luaU:dump(LuaState, func, writer, buff)
f = rerubi(buff.data, env)
end)
if ran then
return f,buff.data
else
return nil,error
end
end
end))
ModuleScript2.Name = "LuaK"
ModuleScript2.Parent = ModuleScript1
table.insert(cors,sandbox(ModuleScript2,function()
--[[--------------------------------------------------------------------
lcode.lua
Lua 5 code generator in Lua
This file is part of Yueliang.
Copyright (c) 2005-2007 Kein-Hong Man <khman@users.sf.net>
The COPYRIGHT file describes the conditions
under which this software may be distributed.
See the ChangeLog for more information.
----------------------------------------------------------------------]]
--[[--------------------------------------------------------------------
-- Notes:
-- * one function manipulate a pointer argument with a simple data type
-- (can't be emulated by a table, ambiguous), now returns that value:
-- luaK:concat(fs, l1, l2)
-- * luaM_growvector uses the faux luaY:growvector, for limit checking
-- * some function parameters changed to boolean, additional code
-- translates boolean back to 1/0 for instruction fields
--
-- Not implemented:
-- * NOTE there is a failed assert in luaK:addk, a porting problem
--
-- Added:
-- * constant MAXSTACK from llimits.h
-- * luaK:ttisnumber(o) (from lobject.h)
-- * luaK:nvalue(o) (from lobject.h)
-- * luaK:setnilvalue(o) (from lobject.h)
-- * luaK:setnvalue(o, x) (from lobject.h)
-- * luaK:setbvalue(o, x) (from lobject.h)
-- * luaK:sethvalue(o, x) (from lobject.h), parameter L deleted
-- * luaK:setsvalue(o, x) (from lobject.h), parameter L deleted
-- * luaK:numadd, luaK:numsub, luaK:nummul, luaK:numdiv, luaK:nummod,
-- luaK:numpow, luaK:numunm, luaK:numisnan (from luaconf.h)
-- * copyexp(e1, e2) added in luaK:posfix to copy expdesc struct
--
-- Changed in 5.1.x:
-- * enum BinOpr has a new entry, OPR_MOD
-- * enum UnOpr has a new entry, OPR_LEN
-- * binopistest, unused in 5.0.x, has been deleted
-- * macro setmultret is new
-- * functions isnumeral, luaK_ret, boolK are new
-- * funcion nilK was named nil_constant in 5.0.x
-- * function interface changed: need_value, patchtestreg, concat
-- * TObject now a TValue
-- * functions luaK_setreturns, luaK_setoneret are new
-- * function luaK:setcallreturns deleted, to be replaced by:
-- luaK:setmultret, luaK:ret, luaK:setreturns, luaK:setoneret
-- * functions constfolding, codearith, codecomp are new
-- * luaK:codebinop has been deleted
-- * function luaK_setlist is new
-- * OPR_MULT renamed to OPR_MUL
----------------------------------------------------------------------]]
-- requires luaP, luaX, luaY
local luaK = {}
local luaP = require(script.Parent.LuaP)
local luaX = require(script.Parent.LuaX)
------------------------------------------------------------------------
-- constants used by code generator
------------------------------------------------------------------------
-- maximum stack for a Lua function
luaK.MAXSTACK = 250 -- (from llimits.h)
--[[--------------------------------------------------------------------
-- other functions
----------------------------------------------------------------------]]
------------------------------------------------------------------------
-- emulation of TValue macros (these are from lobject.h)
-- * TValue is a table since lcode passes references around
-- * tt member field removed, using Lua's type() instead
-- * for setsvalue, sethvalue, parameter L (deleted here) in lobject.h
-- is used in an assert for testing, see checkliveness(g,obj)
------------------------------------------------------------------------
function luaK:ttisnumber(o)
if o then return type(o.value) == "number" else return false end
end
function luaK:nvalue(o) return o.value end
function luaK:setnilvalue(o) o.value = nil end
function luaK:setsvalue(o, x) o.value = x end
luaK.setnvalue = luaK.setsvalue
luaK.sethvalue = luaK.setsvalue
luaK.setbvalue = luaK.setsvalue
------------------------------------------------------------------------
-- The luai_num* macros define the primitive operations over numbers.
-- * this is not the entire set of primitive operations from luaconf.h
-- * used in luaK:constfolding()
------------------------------------------------------------------------
function luaK:numadd(a, b) return a + b end
function luaK:numsub(a, b) return a - b end
function luaK:nummul(a, b) return a * b end
function luaK:numdiv(a, b) return a / b end
function luaK:nummod(a, b) return a % b end
-- ((a) - floor((a)/(b))*(b)) /* actual, for reference */
function luaK:numpow(a, b) return a ^ b end
function luaK:numunm(a) return -a end
function luaK:numisnan(a) return not a == a end
-- a NaN cannot equal another NaN
--[[--------------------------------------------------------------------
-- code generator functions
----------------------------------------------------------------------]]
------------------------------------------------------------------------
-- Marks the end of a patch list. It is an invalid value both as an absolute
-- address, and as a list link (would link an element to itself).
------------------------------------------------------------------------
luaK.NO_JUMP = -1
------------------------------------------------------------------------
-- grep "ORDER OPR" if you change these enums
------------------------------------------------------------------------
luaK.BinOpr = {
OPR_ADD = 0, OPR_SUB = 1, OPR_MUL = 2, OPR_DIV = 3, OPR_MOD = 4, OPR_POW = 5,
OPR_CONCAT = 6,
OPR_NE = 7, OPR_EQ = 8,
OPR_LT = 9, OPR_LE = 10, OPR_GT = 11, OPR_GE = 12,
OPR_AND = 13, OPR_OR = 14,
OPR_NOBINOPR = 15,
}
-- * UnOpr is used by luaK:prefix's op argument, but not directly used
-- because the function receives the symbols as strings, e.g. "OPR_NOT"
luaK.UnOpr = {
OPR_MINUS = 0, OPR_NOT = 1, OPR_LEN = 2, OPR_NOUNOPR = 3
}
------------------------------------------------------------------------
-- returns the instruction object for given e (expdesc), was a macro
------------------------------------------------------------------------
function luaK:getcode(fs, e)
return fs.f.code[e.info]
end
------------------------------------------------------------------------
-- codes an instruction with a signed Bx (sBx) field, was a macro
-- * used in luaK:jump(), (lparser) luaY:forbody()
------------------------------------------------------------------------
function luaK:codeAsBx(fs, o, A, sBx)
return self:codeABx(fs, o, A, sBx + luaP.MAXARG_sBx)
end
------------------------------------------------------------------------
-- set the expdesc e instruction for multiple returns, was a macro
------------------------------------------------------------------------
function luaK:setmultret(fs, e)
self:setreturns(fs, e, luaY.LUA_MULTRET)
end
------------------------------------------------------------------------
-- there is a jump if patch lists are not identical, was a macro
-- * used in luaK:exp2reg(), luaK:exp2anyreg(), luaK:exp2val()
------------------------------------------------------------------------
function luaK:hasjumps(e)
return e.t ~= e.f
end
------------------------------------------------------------------------
-- true if the expression is a constant number (for constant folding)
-- * used in constfolding(), infix()
------------------------------------------------------------------------
function luaK:isnumeral(e)
return e.k == "VKNUM" and e.t == self.NO_JUMP and e.f == self.NO_JUMP
end
------------------------------------------------------------------------
-- codes loading of nil, optimization done if consecutive locations
-- * used in luaK:discharge2reg(), (lparser) luaY:adjust_assign()
------------------------------------------------------------------------
function luaK:_nil(fs, from, n)
if fs.pc > fs.lasttarget then -- no jumps to current position?
if fs.pc == 0 then -- function start?
if from >= fs.nactvar then
return -- positions are already clean
end
else
local previous = fs.f.code[fs.pc - 1]
if luaP:GET_OPCODE(previous) == "OP_LOADNIL" then
local pfrom = luaP:GETARG_A(previous)
local pto = luaP:GETARG_B(previous)
if pfrom <= from and from <= pto + 1 then -- can connect both?
if from + n - 1 > pto then
luaP:SETARG_B(previous, from + n - 1)
end
return
end
end
end
end
self:codeABC(fs, "OP_LOADNIL", from, from + n - 1, 0) -- else no optimization
end
------------------------------------------------------------------------
--
-- * used in multiple locations
------------------------------------------------------------------------
function luaK:jump(fs)
local jpc = fs.jpc -- save list of jumps to here
fs.jpc = self.NO_JUMP
local j = self:codeAsBx(fs, "OP_JMP", 0, self.NO_JUMP)
j = self:concat(fs, j, jpc) -- keep them on hold
return j
end
------------------------------------------------------------------------
-- codes a RETURN instruction
-- * used in luaY:close_func(), luaY:retstat()
------------------------------------------------------------------------
function luaK:ret(fs, first, nret)
self:codeABC(fs, "OP_RETURN", first, nret + 1, 0)
end
------------------------------------------------------------------------
--
-- * used in luaK:jumponcond(), luaK:codecomp()
------------------------------------------------------------------------
function luaK:condjump(fs, op, A, B, C)
self:codeABC(fs, op, A, B, C)
return self:jump(fs)
end
------------------------------------------------------------------------
--
-- * used in luaK:patchlistaux(), luaK:concat()
------------------------------------------------------------------------
function luaK:fixjump(fs, pc, dest)
local jmp = fs.f.code[pc]
local offset = dest - (pc + 1)
assert(dest ~= self.NO_JUMP)
if math.abs(offset) > luaP.MAXARG_sBx then
luaX:syntaxerror(fs.ls, "control structure too long")
end
luaP:SETARG_sBx(jmp, offset)
end
------------------------------------------------------------------------
-- returns current 'pc' and marks it as a jump target (to avoid wrong
-- optimizations with consecutive instructions not in the same basic block).
-- * used in multiple locations
-- * fs.lasttarget tested only by luaK:_nil() when optimizing OP_LOADNIL
------------------------------------------------------------------------
function luaK:getlabel(fs)
fs.lasttarget = fs.pc
return fs.pc
end
------------------------------------------------------------------------
--
-- * used in luaK:need_value(), luaK:removevalues(), luaK:patchlistaux(),
-- luaK:concat()
------------------------------------------------------------------------
function luaK:getjump(fs, pc)
local offset = luaP:GETARG_sBx(fs.f.code[pc])
if offset == self.NO_JUMP then -- point to itself represents end of list
return self.NO_JUMP -- end of list
else
return (pc + 1) + offset -- turn offset into absolute position
end
end
------------------------------------------------------------------------
--
-- * used in luaK:need_value(), luaK:patchtestreg(), luaK:invertjump()
------------------------------------------------------------------------
function luaK:getjumpcontrol(fs, pc)
local pi = fs.f.code[pc]
local ppi = fs.f.code[pc - 1]
if pc >= 1 and luaP:testTMode(luaP:GET_OPCODE(ppi)) ~= 0 then
return ppi
else
return pi
end
end
------------------------------------------------------------------------
-- check whether list has any jump that do not produce a value
-- (or produce an inverted value)
-- * return value changed to boolean
-- * used only in luaK:exp2reg()
------------------------------------------------------------------------
function luaK:need_value(fs, list)
while list ~= self.NO_JUMP do
local i = self:getjumpcontrol(fs, list)
if luaP:GET_OPCODE(i) ~= "OP_TESTSET" then return true end
list = self:getjump(fs, list)
end
return false -- not found
end
------------------------------------------------------------------------
--
-- * used in luaK:removevalues(), luaK:patchlistaux()
------------------------------------------------------------------------
function luaK:patchtestreg(fs, node, reg)
local i = self:getjumpcontrol(fs, node)
if luaP:GET_OPCODE(i) ~= "OP_TESTSET" then
return false -- cannot patch other instructions
end
if reg ~= luaP.NO_REG and reg ~= luaP:GETARG_B(i) then
luaP:SETARG_A(i, reg)
else -- no register to put value or register already has the value
-- due to use of a table as i, i cannot be replaced by another table
-- so the following is required; there is no change to ARG_C
luaP:SET_OPCODE(i, "OP_TEST")
local b = luaP:GETARG_B(i)
luaP:SETARG_A(i, b)
luaP:SETARG_B(i, 0)
-- *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); /* C */
end
return true
end
------------------------------------------------------------------------
--
-- * used only in luaK:codenot()
------------------------------------------------------------------------
function luaK:removevalues(fs, list)
while list ~= self.NO_JUMP do
self:patchtestreg(fs, list, luaP.NO_REG)
list = self:getjump(fs, list)
end
end
------------------------------------------------------------------------
--
-- * used in luaK:dischargejpc(), luaK:patchlist(), luaK:exp2reg()
------------------------------------------------------------------------
function luaK:patchlistaux(fs, list, vtarget, reg, dtarget)
while list ~= self.NO_JUMP do
local _next = self:getjump(fs, list)
if self:patchtestreg(fs, list, reg) then
self:fixjump(fs, list, vtarget)
else
self:fixjump(fs, list, dtarget) -- jump to default target
end
list = _next
end
end
------------------------------------------------------------------------
--
-- * used only in luaK:code()
------------------------------------------------------------------------
function luaK:dischargejpc(fs)
self:patchlistaux(fs, fs.jpc, fs.pc, luaP.NO_REG, fs.pc)
fs.jpc = self.NO_JUMP
end
------------------------------------------------------------------------
--
-- * used in (lparser) luaY:whilestat(), luaY:repeatstat(), luaY:forbody()
------------------------------------------------------------------------
function luaK:patchlist(fs, list, target)
if target == fs.pc then
self:patchtohere(fs, list)
else
assert(target < fs.pc)
self:patchlistaux(fs, list, target, luaP.NO_REG, target)
end
end
------------------------------------------------------------------------
--
-- * used in multiple locations
------------------------------------------------------------------------
function luaK:patchtohere(fs, list)
self:getlabel(fs)
fs.jpc = self:concat(fs, fs.jpc, list)
end
------------------------------------------------------------------------
-- * l1 was a pointer, now l1 is returned and callee assigns the value
-- * used in multiple locations
------------------------------------------------------------------------
function luaK:concat(fs, l1, l2)
if l2 == self.NO_JUMP then return l1
elseif l1 == self.NO_JUMP then
return l2
else
local list = l1
local _next = self:getjump(fs, list)
while _next ~= self.NO_JUMP do -- find last element
list = _next
_next = self:getjump(fs, list)
end
self:fixjump(fs, list, l2)
end
return l1
end
------------------------------------------------------------------------
--
-- * used in luaK:reserveregs(), (lparser) luaY:forlist()
------------------------------------------------------------------------
function luaK:checkstack(fs, n)
local newstack = fs.freereg + n
if newstack > fs.f.maxstacksize then
if newstack >= self.MAXSTACK then
luaX:syntaxerror(fs.ls, "function or expression too complex")
end
fs.f.maxstacksize = newstack
end
end
------------------------------------------------------------------------
--
-- * used in multiple locations
------------------------------------------------------------------------
function luaK:reserveregs(fs, n)
self:checkstack(fs, n)
fs.freereg = fs.freereg + n
end
------------------------------------------------------------------------
--
-- * used in luaK:freeexp(), luaK:dischargevars()
------------------------------------------------------------------------
function luaK:freereg(fs, reg)
if not luaP:ISK(reg) and reg >= fs.nactvar then
fs.freereg = fs.freereg - 1
assert(reg == fs.freereg)
end
end
------------------------------------------------------------------------
--
-- * used in multiple locations
------------------------------------------------------------------------
function luaK:freeexp(fs, e)
if e.k == "VNONRELOC" then
self:freereg(fs, e.info)
end
end
------------------------------------------------------------------------
-- * TODO NOTE implementation is not 100% correct, since the assert fails
-- * luaH_set, setobj deleted; direct table access used instead
-- * used in luaK:stringK(), luaK:numberK(), luaK:boolK(), luaK:nilK()
------------------------------------------------------------------------
function luaK:addk(fs, k, v)
local L = fs.L
local idx = fs.h[k.value]
--TValue *idx = luaH_set(L, fs->h, k); /* C */
local f = fs.f
if self:ttisnumber(idx) then
--TODO this assert currently FAILS (last tested for 5.0.2)
--assert(fs.f.k[self:nvalue(idx)] == v)
--assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); /* C */
return self:nvalue(idx)
else -- constant not found; create a new entry
idx = {}
self:setnvalue(idx, fs.nk)
fs.h[k.value] = idx
-- setnvalue(idx, cast_num(fs->nk)); /* C */
luaY:growvector(L, f.k, fs.nk, f.sizek, nil,
luaP.MAXARG_Bx, "constant table overflow")
-- loop to initialize empty f.k positions not required
f.k[fs.nk] = v
-- setobj(L, &f->k[fs->nk], v); /* C */
-- luaC_barrier(L, f, v); /* GC */
local nk = fs.nk
fs.nk = fs.nk + 1
return nk
end
end
------------------------------------------------------------------------
-- creates and sets a string object
-- * used in (lparser) luaY:codestring(), luaY:singlevar()
------------------------------------------------------------------------
function luaK:stringK(fs, s)
local o = {} -- TValue
self:setsvalue(o, s)
return self:addk(fs, o, o)
end
------------------------------------------------------------------------
-- creates and sets a number object
-- * used in luaK:prefix() for negative (or negation of) numbers
-- * used in (lparser) luaY:simpleexp(), luaY:fornum()
------------------------------------------------------------------------
function luaK:numberK(fs, r)
local o = {} -- TValue
self:setnvalue(o, r)
return self:addk(fs, o, o)
end
------------------------------------------------------------------------
-- creates and sets a boolean object
-- * used only in luaK:exp2RK()
------------------------------------------------------------------------
function luaK:boolK(fs, b)
local o = {} -- TValue
self:setbvalue(o, b)
return self:addk(fs, o, o)
end
------------------------------------------------------------------------
-- creates and sets a nil object
-- * used only in luaK:exp2RK()
------------------------------------------------------------------------
function luaK:nilK(fs)
local k, v = {}, {} -- TValue
self:setnilvalue(v)
-- cannot use nil as key; instead use table itself to represent nil
self:sethvalue(k, fs.h)
return self:addk(fs, k, v)
end
------------------------------------------------------------------------
--
-- * used in luaK:setmultret(), (lparser) luaY:adjust_assign()
------------------------------------------------------------------------
function luaK:setreturns(fs, e, nresults)
if e.k == "VCALL" then -- expression is an open function call?
luaP:SETARG_C(self:getcode(fs, e), nresults + 1)
elseif e.k == "VVARARG" then
luaP:SETARG_B(self:getcode(fs, e), nresults + 1);
luaP:SETARG_A(self:getcode(fs, e), fs.freereg);
luaK:reserveregs(fs, 1)
end
end
------------------------------------------------------------------------
--
-- * used in luaK:dischargevars(), (lparser) luaY:assignment()
------------------------------------------------------------------------
function luaK:setoneret(fs, e)
if e.k == "VCALL" then -- expression is an open function call?
e.k = "VNONRELOC"
e.info = luaP:GETARG_A(self:getcode(fs, e))
elseif e.k == "VVARARG" then
luaP:SETARG_B(self:getcode(fs, e), 2)
e.k = "VRELOCABLE" -- can relocate its simple result
end
end
------------------------------------------------------------------------
--
-- * used in multiple locations
------------------------------------------------------------------------
function luaK:dischargevars(fs, e)
local k = e.k
if k == "VLOCAL" then
e.k = "VNONRELOC"
elseif k == "VUPVAL" then
e.info = self:codeABC(fs, "OP_GETUPVAL", 0, e.info, 0)
e.k = "VRELOCABLE"
elseif k == "VGLOBAL" then
e.info = self:codeABx(fs, "OP_GETGLOBAL", 0, e.info)
e.k = "VRELOCABLE"
elseif k == "VINDEXED" then
self:freereg(fs, e.aux)
self:freereg(fs, e.info)
e.info = self:codeABC(fs, "OP_GETTABLE", 0, e.info, e.aux)
e.k = "VRELOCABLE"
elseif k == "VVARARG" or k == "VCALL" then
self:setoneret(fs, e)
else
-- there is one value available (somewhere)
end
end
------------------------------------------------------------------------
--
-- * used only in luaK:exp2reg()
------------------------------------------------------------------------
function luaK:code_label(fs, A, b, jump)
self:getlabel(fs) -- those instructions may be jump targets
return self:codeABC(fs, "OP_LOADBOOL", A, b, jump)
end
------------------------------------------------------------------------
--
-- * used in luaK:discharge2anyreg(), luaK:exp2reg()
------------------------------------------------------------------------
function luaK:discharge2reg(fs, e, reg)
self:dischargevars(fs, e)
local k = e.k
if k == "VNIL" then
self:_nil(fs, reg, 1)
elseif k == "VFALSE" or k == "VTRUE" then
self:codeABC(fs, "OP_LOADBOOL", reg, (e.k == "VTRUE") and 1 or 0, 0)
elseif k == "VK" then
self:codeABx(fs, "OP_LOADK", reg, e.info)
elseif k == "VKNUM" then
self:codeABx(fs, "OP_LOADK", reg, self:numberK(fs, e.nval))
elseif k == "VRELOCABLE" then
local pc = self:getcode(fs, e)
luaP:SETARG_A(pc, reg)
elseif k == "VNONRELOC" then
if reg ~= e.info then
self:codeABC(fs, "OP_MOVE", reg, e.info, 0)
end
else
assert(e.k == "VVOID" or e.k == "VJMP")
return -- nothing to do...
end
e.info = reg
e.k = "VNONRELOC"
end
------------------------------------------------------------------------
--
-- * used in luaK:jumponcond(), luaK:codenot()
------------------------------------------------------------------------
function luaK:discharge2anyreg(fs, e)
if e.k ~= "VNONRELOC" then
self:reserveregs(fs, 1)
self:discharge2reg(fs, e, fs.freereg - 1)
end
end
------------------------------------------------------------------------
--
-- * used in luaK:exp2nextreg(), luaK:exp2anyreg(), luaK:storevar()
------------------------------------------------------------------------
function luaK:exp2reg(fs, e, reg)
self:discharge2reg(fs, e, reg)
if e.k == "VJMP" then
e.t = self:concat(fs, e.t, e.info) -- put this jump in 't' list
end
if self:hasjumps(e) then
local final -- position after whole expression
local p_f = self.NO_JUMP -- position of an eventual LOAD false
local p_t = self.NO_JUMP -- position of an eventual LOAD true
if self:need_value(fs, e.t) or self:need_value(fs, e.f) then
local fj = (e.k == "VJMP") and self.NO_JUMP or self:jump(fs)
p_f = self:code_label(fs, reg, 0, 1)
p_t = self:code_label(fs, reg, 1, 0)
self:patchtohere(fs, fj)
end
final = self:getlabel(fs)
self:patchlistaux(fs, e.f, final, reg, p_f)
self:patchlistaux(fs, e.t, final, reg, p_t)
end
e.f, e.t = self.NO_JUMP, self.NO_JUMP
e.info = reg
e.k = "VNONRELOC"
end
------------------------------------------------------------------------
--
-- * used in multiple locations
------------------------------------------------------------------------
function luaK:exp2nextreg(fs, e)
self:dischargevars(fs, e)
self:freeexp(fs, e)
self:reserveregs(fs, 1)
self:exp2reg(fs, e, fs.freereg - 1)
end
------------------------------------------------------------------------
--
-- * used in multiple locations
------------------------------------------------------------------------
function luaK:exp2anyreg(fs, e)
self:dischargevars(fs, e)
if e.k == "VNONRELOC" then
if not self:hasjumps(e) then -- exp is already in a register
return e.info
end
if e.info >= fs.nactvar then -- reg. is not a local?
self:exp2reg(fs, e, e.info) -- put value on it
return e.info
end
end
self:exp2nextreg(fs, e) -- default
return e.info
end
------------------------------------------------------------------------
--
-- * used in luaK:exp2RK(), luaK:prefix(), luaK:posfix()
-- * used in (lparser) luaY:yindex()
------------------------------------------------------------------------
function luaK:exp2val(fs, e)
if self:hasjumps(e) then
self:exp2anyreg(fs, e)
else
self:dischargevars(fs, e)
end
end
------------------------------------------------------------------------
--
-- * used in multiple locations
------------------------------------------------------------------------
function luaK:exp2RK(fs, e)
self:exp2val(fs, e)
local k = e.k
if k == "VKNUM" or k == "VTRUE" or k == "VFALSE" or k == "VNIL" then
if fs.nk <= luaP.MAXINDEXRK then -- constant fit in RK operand?
-- converted from a 2-deep ternary operator expression
if e.k == "VNIL" then
e.info = self:nilK(fs)
else
e.info = (e.k == "VKNUM") and self:numberK(fs, e.nval)
or self:boolK(fs, e.k == "VTRUE")
end
e.k = "VK"
return luaP:RKASK(e.info)
end
elseif k == "VK" then
if e.info <= luaP.MAXINDEXRK then -- constant fit in argC?
return luaP:RKASK(e.info)
end
else
-- default
end
-- not a constant in the right range: put it in a register
return self:exp2anyreg(fs, e)
end
------------------------------------------------------------------------
--
-- * used in (lparser) luaY:assignment(), luaY:localfunc(), luaY:funcstat()
------------------------------------------------------------------------
function luaK:storevar(fs, var, ex)
local k = var.k
if k == "VLOCAL" then
self:freeexp(fs, ex)
self:exp2reg(fs, ex, var.info)
return
elseif k == "VUPVAL" then
local e = self:exp2anyreg(fs, ex)
self:codeABC(fs, "OP_SETUPVAL", e, var.info, 0)
elseif k == "VGLOBAL" then
local e = self:exp2anyreg(fs, ex)
self:codeABx(fs, "OP_SETGLOBAL", e, var.info)
elseif k == "VINDEXED" then
local e = self:exp2RK(fs, ex)
self:codeABC(fs, "OP_SETTABLE", var.info, var.aux, e)
else
assert(0) -- invalid var kind to store
end
self:freeexp(fs, ex)
end
------------------------------------------------------------------------
--
-- * used only in (lparser) luaY:primaryexp()
------------------------------------------------------------------------
function luaK:_self(fs, e, key)
self:exp2anyreg(fs, e)
self:freeexp(fs, e)
local func = fs.freereg