-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathxlua.txt
1507 lines (1030 loc) · 58.2 KB
/
xlua.txt
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
xlua版本 3.3
-------- -------- -------- --------
AES
-------- -------- -------- --------
AES加密:使用padding时,自动pkcs7padding。否则不对齐部分不加密,忽略之
AES解密:不对齐部分不解密,忽略之
不使用padding时,默认块大小==16
提供的KEY长度不足16时,以0补足
●
string aes_ecb_pkcs7padding_encrypt
(
string data,
string key
[,
int block_size = 16
]
); [-2|3, +1, c|v]
string aes_ecb_pkcs7padding_decrypt
(
string data,
string key
[,
int block_size = 16
]
); [-2|3, +1, c|v]
string aes.ecb.p7enc ( ... ); [-2|3, +1, c|v]
string aes.ecb.p7dec ( ... ); [-2|3, +1, c|v]
string string:aes_ecb_p7_enc ( ... ); [-1|2, +1, c|v]
string string:aes_ecb_p7_dec ( ... ); [-1|2, +1, c|v]
string aes_cbc_pkcs7padding_encrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 16
]
); [-2|3|4, +1, c|v]
string aes_cbc_pkcs7padding_decrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 16
]
); [-2|3|4, +1, c|v]
string aes.cbc.p7enc ( ... ); [-2|3|4, +1, c|v]
string aes.cbc.p7dec ( ... ); [-2|3|4, +1, c|v]
string string:aes_cbc_p7_enc ( ... ); [-1|2|3, +1, c|v]
string string:aes_cbc_p7_dec ( ... ); [-1|2|3, +1, c|v]
-------- -------- -------- --------
string aes_ecb_encrypt
(
string data,
string key
[,
int block_size = 16
]
); [-2|3, +1, c|v]
string aes_ecb_decrypt
(
string data,
string key
[,
int block_size = 16
]
); [-2|3, +1, c|v]
string aes.ecb.enc ( ... ); [-2|3, +1, c|v]
string aes.ecb.enc ( ... ); [-2|3, +1, c|v]
string string:aes_ecb_enc ( ... ); [-1|2, +1, c|v]
string string:aes_ecb_dec ( ... ); [-1|2, +1, c|v]
string aes_cbc_encrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 16
]
); [-2|3|4, +1, c|v]
string aes_cbc_decrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 16
]
); [-2|3|4, +1, c|v]
string aes.cbc.enc ( ... ); [-2|3|4, +1, c|v]
string aes.cbc.dec ( ... ); [-2|3|4, +1, c|v]
string string:aes_cbc_enc ( ... ); [-1|2|4, +1, c|v]
string string:aes_cbc_dec ( ... ); [-1|2|4, +1, c|v]
-------- -------- -------- --------
algorithm操作
-------- -------- -------- --------
●
int xrand ( [int mod = 0] ); [-0|1, +1, -]
●
string strxor ( string data, int xor ); [-2, +1, -]
string string:;xor ( int xor ); [-1, +1, -]
●
string md5 ( string data ); [-1, +1, c]
string string:md5 ( ); [-0, +1, -]
●
int crc16 ( string data ); [-1, +1, c]
int crc32 ( string data ); [-1, +1, c]
int crc64 ( string data ); [-1, +1, c]
int string:crc16 ( ); [-0, +1, -]
int string:crc32 ( ); [-0, +1, -]
int string:crc64 ( ); [-0, +1, -]
●
string TeanEncrypt ( string data, string key ); [-2, +1, c]
string TeanDecrypt ( string data, string key ); [-2, +1, c]
string TeaEncrypt (
string data,
string key,
int delta,
int round
); [-4, +1, c]
string TeaDecrypt (
string data,
string key,
int delta,
int round
); [-4, +1, c]
string TeanEncipher ( string data, string key ); [-2, +1, c]
string TeanDecipher ( string data, string key ); [-2, +1, c]
string XTeanEncrypt ( string data, string key ); [-2, +1, c]
string XTeanDecrypt ( string data, string key ); [-2, +1, c]
string XxTeaEncrypt ( string data, string key ); [-2, +1, c]
string XxTeaDecrypt ( string data, string key ); [-2, +1, c]
string string:tean_enc ( string key ); [-1, +1, c]
string string:tean_dec ( string key ); [-1, +1, c]
string string:tea_enc ( string key, int delta, int round ); [-3, +1, c]
string string:tea_dec ( string key, int delta, int round ); [-3, +1, c]
string string:tea_enr ( string key ); [-1, +1, c]
string string:tea_der ( string key ); [-1, +1, e]
string string:xtean_enc( string key ); [-1, +1, e]
string string:xtean_dec( string key ); [-1, +1, e]
string string:xxtea_enc( string key ); [-1, +1, e]
string string:xxtea_dec( string key ); [-1, +1, e]
●
string aes_encrypt ( string data, string key ); [-2, +1, c]
string aes_decrypt ( string data, string key ); [-2, +1, c]
string string:aes_enc ( string key ); [-1, +1, c]
string string:aes_dec ( string key ); [-1, +1, c]
-------- -------- -------- --------
BLOWFISH
-------- -------- -------- --------
BLOWFISH加密:使用padding时,自动pkcs7padding。否则不对齐部分不加密,忽略之
BLOWFISH解密:不对齐部分不解密,忽略之
不使用padding时,默认块大小==8
提供的KEY长度不足8时,以0补足
●
string blowfish_ecb_pkcs7padding_encrypt
(
string data,
string key
); [-2|3, +1, c|v]
string blowfish_ecb_pkcs7padding_decrypt
(
string data,
string key
); [-2|3, +1, c|v]
string blowfish.ecb.p7enc ( ... ); [-2|3, +1, c|v]
string blowfish.ecb.p7dec ( ... ); [-2|3, +1, c|v]
string string:bf_ecb_p7_enc ( ... ); [-1|2, +1, c|v]
string string:bf_ecb_p7_dec ( ... ); [-1|2, +1, c|v]
string blowfish_cbc_pkcs7padding_encrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0"
]
); [-2|3|4, +1, c|v]
string blowfish_cbc_pkcs7padding_decrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 16
]
); [-2|3|4, +1, c|v]
string blowfish.cbc.p7enc ( ... ); [-2|3|4, +1, c|v]
string blowfish.cbc.p7dec ( ... ); [-2|3|4, +1, c|v]
string string:bf_cbc_p7_enc ( ... ); [-1|2|3, +1, c|v]
string string:bf_cbc_p7_dec ( ... ); [-1|2|3, +1, c|v]
-------- -------- -------- --------
string blowfish_ecb_encrypt
(
string data,
string key
[,
int block_size = 16
]
); [-2|3, +1, c|v]
string blowfish_ecb_decrypt
(
string data,
string key
[,
int block_size = 16
]
); [-2|3, +1, c|v]
string blowfish.ecb.enc ( ... ); [-2|3, +1, c|v]
string blowfish.ecb.enc ( ... ); [-2|3, +1, c|v]
string string:bf_ecb_enc ( ... ); [-1|2, +1, c|v]
string string:bf_ecb_dec ( ... ); [-1|2, +1, c|v]
string blowfish_cbc_encrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 16
]
); [-2|3|4, +1, c|v]
string blowfish_cbc_decrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 16
]
); [-2|3|4, +1, c|v]
string blowfish.cbc.enc ( ... ); [-2|3|4, +1, c|v]
string blowfish.cbc.dec ( ... ); [-2|3|4, +1, c|v]
string string:bf_cbc_enc ( ... ); [-1|2|4, +1, c|v]
string string:bf_cbc_dec ( ... ); [-1|2|4, +1, c|v]
-------- -------- -------- --------
DES
-------- -------- -------- --------
DES加密:使用padding时,自动pkcs7padding。否则不对齐部分不加密,忽略之
DES解密:不对齐部分不解密,忽略之
不使用padding时,默认块大小==8
提供的KEY长度不足8时,以0补足
●
string des_ecb_pkcs7padding_encrypt
(
string data,
string key
[,
int block_size = 8
]
); [-2|3, +1, c]
string des_ecb_pkcs7padding_decrypt
(
string data,
string key
[,
int block_size = 8
]
); [-2|3, +1, c|v]
string des.ecb.p7enc ( ... ); [-2|3, +1, c]
string des.ecb.p7dec ( ... ); [-2|3, +1, c|v]
string string:des_ecb_p7_enc ( ... ); [-1|2, +1, c]
string string:des_ecb_p7_dec ( ... ); [-1|2, +1, c|v]
string des_cbc_pkcs7padding_encrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 8
]
); [-2|3|4, +1, c]
string des_cbc_pkcs7padding_decrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 8
]
); [-2|3|4, +1, c|v]
string des.cbc.p7enc ( ... ); [-2|3|4, +1, c]
string des.cbc.p7dec ( ... ); [-2|3|4, +1, c|v]
string string:des_cbc_p7_enc ( ... ); [-1|2|3, +1, c]
string string:des_cbc_p7_dec ( ... ); [-1|2|3, +1, c|v]
string des_ncbc_pkcs7padding_encrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 8
]
); [-2|3|4, +1, c]
string des_ncbc_pkcs7padding_decrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 8
]
); [-2|3|4, +1, c|v]
string des.ncbc.p7enc ( ... ); [-2|3|4, +1, c]
string des.ncbc.p7dec ( ... ); [-2|3|4, +1, c|v]
string string:des_ncbc_p7_enc ( ... ); [-1|2|3, +1, c]
string string:des_ncbc_p7_dec ( ... ); [-1|2|3, +1, c|v]
-------- -------- -------- --------
string des_ecb_encrypt
(
string data,
string key
[,
int block_size = 8
]
); [-2|3, +1, c]
string des_ecb_decrypt
(
string data,
string key
[,
int block_size = 8
]
); [-2|3, +1, c|v]
string des.ecb.enc ( ... ); [-2|3, +1, c]
string des.ecb.enc ( ... ); [-2|3, +1, c|v]
string string:des_ecb_enc ( ... ); [-1|2, +1, c]
string string:des_ecb_dec ( ... ); [-1|2, +1, c|v]
string des_cbc_encrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 8
]
); [-2|3|4, +1, c]
string des_cbc_decrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 8
]
); [-2|3|4, +1, c|v]
string des.cbc.enc ( ... ); [-2|3|4, +1, c]
string des.cbc.dec ( ... ); [-2|3|4, +1, c|v]
string string:des_cbc_enc ( ... ); [-1|2|4, +1, c]
string string:des_cbc_dec ( ... ); [-1|2|4, +1, c|v]
string des_ncbc_encrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 8
]
); [-2|3|4, +1, c]
string des_ncbc_decrypt
(
string data,
string key
[,
string ivec = "\0\0\0\0\0\0\0\0",
int block_size = 8
]
); [-2|3|4, +1, c|v]
string des.ncbc.enc ( ... ); [-2|3|4, +1, c]
string des.ncbc.dec ( ... ); [-2|3|4, +1, c|v]
string string:des_ncbc_enc ( ... ); [-1|2|3, +1, c]
string string:des_ncbc_dec ( ... ); [-1|2|3, +1, c|v]
-------- -------- -------- --------
hex&str操作
-------- -------- -------- --------
●
string str2hexs (
string str
[,
bool errexit = false,
bool errbreak = false
]
); [-1|2|3, +1, c]
string hex2show (
string data
[,
int prews = 0,
string code = "u"|"8"|"a",
bool isup = true
]
); [-1|2|3|4, +1, c]
string hex2str (
string data
[,
bool isup = false
]
); [-1|2, +1, c]
string string:str2hexs (
[
bool errexit = false,
bool errbreak = false
]
); [-0|1|2, +1, -]
string string:hex2show (
[
int prews = 0,
string code = "u"|"8"|"a",
bool isup = true
]
); [-0|1|2|3, +1, c]
string string:hex2str (
[
bool isup = false
]
); [-0|1, +1, -]
-------- -------- -------- --------
mem操作
-------- -------- -------- --------
●
string readmem ( void* lpmem, size_t size ); [-2, +1, c]
--读取指定内存位置指定长度数据
--以下函数需要5.3及以上的string.unpack支持。低版本请自行修改源码添加之
int mkb ( void* lpmem ); --读取有符号byte值,小端 [-1, +1, c|e]
int mkB ( void* lpmem ); --读取无符号byte值,小端 [-1, +1, c|e]
int mkbb ( void* lpmem ); --读取有符号byte值,大端 [-1, +1, c|e]
int mkBB ( void* lpmem ); --读取无符号byte值,大端 [-1, +1, c|e]
int mkw ( void* lpmem ); --读取有符号word值,小端 [-1, +1, c|e]
int mkW ( void* lpmem ); --读取无符号word值,小端 [-1, +1, c|e]
int mkww ( void* lpmem ); --读取有符号word值,大端 [-1, +1, c|e]
int mkWW ( void* lpmem ); --读取无符号word值,大端 [-1, +1, c|e]
int mkd ( void* lpmem ); --读取有符号dword值,小端 [-1, +1, c|e]
int mkD ( void* lpmem ); --读取无符号dword值,小端 [-1, +1, c|e]
int mkdd ( void* lpmem ); --读取有符号dword值,大端 [-1, +1, c|e]
int mkDD ( void* lpmem ); --读取无符号dword值,大端 [-1, +1, c|e]
float mkf ( void* lpmem ); --读取float值,小端 [-1, +1, c|e]
double mkF ( void* lpmem ); --读取double值,小端 [-1, +1, c|e]
float mkff ( void* lpmem ); --读取float值,大端 [-1, +1, c|e]
double mkFF ( void* lpmem ); --读取double值,大端 [-1, +1, c|e]
-------- -------- -------- --------
openssl操作
-------- -------- -------- --------
● private: RsaKey;
void RsaKey:__gc ( ); [-0, +0, c]
string RsaKey:__tostring ( ); [-0, +1, c]
--返回"RsaKey*:####"
●
RsaKey rsa_open_public_key ( string filename ); [-1, +1, v]
RsaKey rsa_set_public_key ( string rsakey ); [-1, +1, v]
RsaKey rsa_open_private_key ( string filename ); [-1, +1, v]
RsaKey rsa_set_private_key ( string rsakey ); [-1, +1, v]
string rsa_public_encrypt ( string data, RsaKey key ); [-2, +1, c|v]
string rsa_private_encrypt ( string data, RsaKey key ); [-2, +1, c|e]
string rsa_public_decrypt ( string data, RsaKey key ); [-2, +1, c|e]
string rsa_private_decrypt ( string data, RsaKey key ); [-2, +1, c|e]
●
RsaKey rsa.pub.open ( string filename ); [-1, +1, v]
RsaKey rsa.pub.set ( string rsakey ); [-1, +1, v]
string rsa.pub.enc ( string data, RsaKey key ); [-2, +1, c|e]
string rsa.pub.dec ( string data, RsaKey key ); [-2, +1, c|e]
RsaKey rsa.prv.open ( string filename ); [-1, +1, v]
RsaKey rsa.prv.set ( string rsakey ); [-1, +1, v]
string rsa.prv.enc ( string data, RsaKey key ); [-2, +1, c|e]
string rsa.prv.dec ( string data, RsaKey key ); [-2, +1, c|e]
string string:rsa_pub_enc ( RsaKey key ); [-1, +1, c|e]
string string:rsa_pub_dec ( RsaKey key ); [-1, +1, c|e]
string string:rsa_prv_enc ( RsaKey key ); [-1, +1, c|e]
string string:rsa_prv_dec ( RsaKey key ); [-1, +1, c|e]
string des_encrypt ( string data, string key ); [-2, +1, c]
string des_decrypt ( string data, string key ); [-2, +1, c|v]
string string:des_enc ( string key ); [-1, +1, c]
string string:des_dec ( string key ); [-1, +1, c|v]
string base64_encode (
string data
[,
bool newline = false
]
); [-1|2, +1, c]
string base64_decode (
string data
[,
bool newline = false
]
); [-1|2, +1, c]
string string:b64_enc ( [bool newline = false] ); [-0|1, +1, c]
string string:b64_dec ( [bool newline = false] ); [-0|1, +1, c]
string sha (
string data
[,
int algo = 256
]
); [-1|2, +1, c]
--sha支持的algo有256/512/1/0/224/384
string string:sha ( [int algo] ); [-0|1, +1, c]
--以下是SHA便捷函数组
string sha0 ( string data ); [-1, +1, c]
string sha1 ( string data ); [-1, +1, c]
string sha224 ( string data ); [-1, +1, c]
string sha256 ( string data ); [-1, +1, c]
string sha384 ( string data ); [-1, +1, c]
string sha512 ( string data ); [-1, +1, c]
string string:sha0 ( ); [-0, +1, c]
string string:sha1 ( ); [-0, +1, c]
string string:sha224 ( ); [-0, +1, c]
string string:sha256 ( ); [-0, +1, c]
string string:sha384 ( ); [-0, +1, c]
string string:sha512 ( ); [-0, +1, c]
string hmac (
string data,
string key,
string algo
); [-3, +1, c]
--hmac支持的algo有"sha512/sha256/sha1/md5/sha224/sha384/sha"
string string:hmac ( string key, string algo ); [-2, +1, c]
-------- -------- -------- --------
serialcomm操作
-------- -------- -------- --------
●
string[] serialcomm.gets ( ); [-0, +1, v]
--获取串行通讯口列表
--返回表如下:
{
string serialcomm_1 ( "COM#" ),
string serialcomm_2,
...
}
SerailComm serialcomm.raw_open ( string SerialCommName ); [-1, +1, c|v]
--指定串口名称,打开串口
--返回打开成功的串口对象
--此函数为原始打开,并未记录已打开的串口对象,无法通过serialcomm.close自动释放,建议使用serialcomm.open函数
●
SerialComm[] serialcomm.opened;
--保存使用serialcomm.open打开的串口对象,以便查询或通过serialcomm.close自动释放
--开放此表是为了方便查询,用户不应修改此表,以免造成serialcomm.close无法自动释放所有已打开的串口对象
--表格式如示:{ SerailComm, SerailComm, ... };
ex:
for k, v in pairs(serialcomm.opened) do
xlog(k ,v);
end
SerailComm serialcomm.open ( string SerialCommName ); [-1, +1, c|v]
--指定串口名称,打开串口,同时保存已经打开的对象至表serialcomm.opened
--使用此函数打开的串口对象可以使用serialcomm.close自动释放
void serialcomm.close ( ); [-0, +0, c]
--释放表serialcomm.opened中所有的SerialComm对象并清空表
●
private: SerialComm;
以下函数为串口对象操作函数
未作特别说明情况下,串口对象操作失败,将抛出异常,同时!!释放串口对象!!
string SerialComm:__tostring ( ); [-0, +1, c]
--输出串口对象信息
--信息格式如示:"SerialComm [COM#] (Closed & N/A | Invalid | ####)"
void SerialComm:__gc ( ); [-0, +0, c]
--串口对象释放
--如果串口对象有效,返回true,否则返回false
bool SerialComm:close ( ); [-0, +0, c]
--同SerialComm:__gc,用于主动释放串口对象
int SerialComm:baudrate ( [int newvalue] ); [-0|1, +1, c|v]
--当指定newvalue时,设置串口对象BaudRate,同时返回旧值
--未指定newvalue时,仅仅返回当前BaudRate
--以下几个函数同理
int SerialComm:bytesize ( [int newvalue] ); [-0|1, +1, c|v]
int SerialComm:stopbits ( [int newvalue] ); [-0|1, +1, c|v]
int SerialComm:parity ( [int newvalue] ); [-0|1, +1, c|v]
int SerialComm:write ( string data ); [-1, +1, c|v]
--指定写入数据到串口对象,返回写入数据字节数
--保证将指定数据全部写入串口对象
string SerialComm:read ( ); [-0, +1, c|v]
--从串口对象读取数据
--如果串口无数据,返回空串
HANDLE SerialComm:handle ( ); --返回串口对象句柄 [-0, +1, c]
bool SerialComm:isopen ( ); --检测串口有效性 [-0, +1, c]
string SerialComm:name ( ); --返回串口名称,如:"COM#"[-0, +1, c]
string SerialComm:type ( ); --返回串口类型"SerialComm"[-0, +1, c]
-------- -------- -------- --------
sock操作
-------- -------- -------- --------
●
Private: UDP;
--UDP操作失败将抛出异常,同时!!释放对象!!
UDP udp_new (
[
string|uint ip = "0.0.0.0",
string|uint port = "0",
string|uint bind_port = "0"
]
); [-0|1|2|3, +1, c|v]
--当ip == "0.0.0.0"且port != "0"时,绑定指定端口
--当ip != "0.0.0.0"时,默认连接指定IP,此时,启用bind_port为绑定端口
string ip, string port, uint ip, uint port
UDP:getsockname ( ); [-0, +1, c]
string ip, string port, uint ip, uint port
UDP:getpeername ( ); [-0, +1, c]
stirng UDP:type ( ); --返回"UDP" [-0, +1, c]
void UDP:close ( ); [-0, +0, c]
void UDP:__gc ( ); [-0, +0, c]
string UDP:__tostring ( ); [-0, +1, c]
--返回UDP{server/client}:######## local_ip:port >> link_ip:port
UDP UDP:settimeout ( int timeout ); [-1, +1, v]
--接收延时,毫秒计
UDP UDP:broadcast ( bool set ); [-1, +1, v]
--广播设置
UDP UDP:send (
string data
[,
string|uint ip = "0.0.0.0",
string|uint port = "0"
]
); [-1|2|3, +1, c|v]
--当不提供ip、port时,默认连接初始化时指定的IP
string data, string ip, string port, uint ip, uint port
UDP:recv ( [ int size = 0x800 ] ); [-0|1, +2|5, c|v]
--当不提供size时,默认提供0x800的接收缓冲区
--超时返回nil, "timeout"
--接收缓冲区不足返回nil, "msgsize"
●
Private: TCP;
--TCP操作失败将抛出异常,同时!!释放对象!!
TCP tcp_new (
string|uint ip = "0.0.0.0"
string|uint port = "0",
string|uint bind_port = "0"
); [-3, +1, c|v]
string ip, string port, uint ip, uint port
TCP:getsockname ( ); [-0, +1, c]
string ip, string port, uint ip, uint port
TCP:getpeername ( ); [-0, +1, c]
stirng TCP:type ( ); --返回"TCP" [-0, +1, c]
void TCP:close ( ); [-0, +0, c]
void TCP:__gc ( ); [-0, +0, c]
string TCP:__tostring ( ); [-0, +1, c]
--返回TCP{server/client}:######## local_ip:port >> link_ip:port
TCP TCP:settimeout ( int timeout ); [-1, +1, v]
--接收延时,毫秒计。Server不支持
TCP TCP:broadcast ( bool set ); [-1, +1, v]
--广播设置。Server不支持
TCP TCP:send ( string data ); [-1, +1, c|v]
--发送数据。Server不支持
string TCP:recv ( [ int size = 0x800 ] ); [-0|1, +1|2, c|v]
--当不提供size时,默认提供0x800的接收缓冲区
--超时返回nil, "timeout"。Server不支持
TCP TCP:accept ( [ int timeout == -1 ]); [-0|1, +1|2, v]
--Client不支持
--当不提供timeout时,默认超时值-1,即阻塞直到连接发生
--当提供timeout(毫秒计)时,阻塞指定时间,直到连接发生或超时返回
--连接发生时,返回新连接的TCP对象
--超时返回nil, "timeout"
-------- -------- -------- --------
s&ws操作
-------- -------- -------- --------
●
string ws2s ( string s ); --unicode转换为ascii [-1, +1, c]
string s2ws ( string ws ); --ascii转换为unicode [-1, +1, c]
string string:ws2s ( ); --unicode转换为ascii [-0, +1, -]
string string:s2ws ( ); --ascii转换为unicode [-0, +1, -]
-------- -------- -------- --------
utf8操作
-------- -------- -------- --------
●
string utf82ws ( string utf8 ); --utf8转换为unicode [-1, +1, c]
string ws2utf8 ( string ws ); --unicode转换为utf8 [-1, +1, c]
string utf82s ( string utf8 ); --utf8转换为ascii [-1, +1, c]
string s2utf8 ( string s ); --ascii转换为utf8 [-1, +1, c]
string string:utf82ws ( ); [-0, +1, -]
string string:ws2utf8 ( ); [-0, +1, -]
string string:utf82s ( ); [-0, +1, -]
string string:s2utf8 ( ); [-0, +1, -]
-------- -------- -------- --------
api操作
-------- -------- -------- --------
●
void sleep ( [int ms = 0] ); [-0|1, +0, -]
--暂停线程ms毫秒,ms允许为空
int gettick ( ); [-0, +1, -]
--获取系统启动时间毫秒数
-------- -------- -------- --------
xhttp操作
-------- -------- -------- --------
●
int response_code, table response_headers, string response_body
xhttp (
string url
[,
table options
]
);
[-1|2, +3, v]
--进行一次http访问
--options表可以设置如下参数(注意小写名称):
{
int connect_time_out; --连接超时,毫秒计,默认20000
int time_out; --访问超时,毫秒计,默认10000
string proxy; --代理
此项存在且不为空时,设置代理
string data; --post数据
此项存在时,http访问为post。否则默认为get
table header; --访问头
}
--访问头、响应头表以[键名] = 值形式组表
ex:
local c, h, b = xhttp("http://www.hj032.cn");
for k, v in pairs(h) do
xlog("key:" .. k, "value:" .. v);
end
local c, h, b = xhttp("http://www.xxxx.xx",
{
connect_time_out = 10000,
time_out = 500,
proxy = "127.0.0.1:8080",
data = "post data",
header =
{
xxx = "xxxx";
}
}
);
-------- -------- -------- --------
xline操作
-------- -------- -------- --------
●
xline xline:new ( ); [-0, +1, -]
--xline需要5.3及以上的string.pack,string.unpack支持。低版本请自行修改源码添加之
--提供xline时,复制xline状态及内容
--未提供状态时,默认小端,头大小2 byte,不包含头,不处理结尾0
--xline数据项说明:
line 数据内容(string)
net_flag 数据处理编码(boolean),true大端 false小端,默认小端
0x1234大端写入,内容为"\x12\x34",小端写入,内容为"\x34\x12"
head_size 数据处理头大小(int),1byte 2word 4dword,默认2
"AA"作为line写入时,内容为"\x02\x00\x41\x41"
head_self 数据处理头是否包含头大小(boolean)
"AA"作为line,且包含头大小写入时,内容为"\x04\x00\x41\x41"
deal_zero_end 数据处理结尾0
写入字符串时,额外写入结尾0
读取字符串,额外读出结尾0
nets 根据net_flag决定为大端">"或小端"<"
●
xline xline:newline ( [string] ); [-0|1, +1, -]
--指定数据内容,初始化为xline
●
... xline:pick ( string fmt ); [-1, +?, e]
--指定读取格式,读取数据并修改处理索引
int xline:get_byte ( ); --读取一个byte [-0, +1, e]
int xline:get_word ( ); --读取一个word [-0, +1, e]
int xline:get_dword ( ); --读取一个dword [-0, +1, e]
int head_size, int real_size
xline:get_head ( ); [-0, +2, e]
--读取数据头,返回数据头值、真实数据头值(减去可能包含的数据头大小)
xline xline:get_line ( [int size] ); [-0|1, +1, e]
--读取指定大小数据,生成新的xline,同时复制状态
--如果size <= 0或未指定,复制新的xline,原始xline数据内容清除,索引置1
xline newline, int rawsize
xline:get_head_line ( ); [-0, +2, e]
--读取带数据头的一组数据
--返回生成新的xline,以及数据头原始大小
string xline:get_str (
[
int size,
int type_size = 1
]
); [-0|1|2, +1, e]
--读取指定长度字符串,以字符串类型大小计
--长度未提供时,提取以0结尾的字符串
--类型大小未提供时,默认为1,即ascii字符串
string xline:get_ascii_str ( [int size] ); [-0|1, +1, e]
--读取指定长度ascii字符串
string xline:get_unicode_str ( [int size] ); [-0|1, +1, e]
--读取指定长度unicode字符串
string xline:get_head_ascii ( [int size] ); [-0|1, +1, e]
--读取带头的ascii字符串
string xline:get_head_unicode ( [int size] ); [-0|1, +1, e]
--读取带头的unicode字符串
●
xline xline:clear ( ); [-0, +1, -]
--清除数据内容