-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclass_from_avm2spec.pl
executable file
·73 lines (56 loc) · 1.05 KB
/
class_from_avm2spec.pl
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
sub fix_name {
$type = @_[0];
$type =~ s/'//g;
$newtype = '';
foreach $_ (split (/_/, $type)) {
s/(\w)(.*)/uc($1).$2/eg;
$newtype .= $_;
}
return $newtype;
}
my $actionscript_ints = 1;
my @lines = ();
my $classname = <>;
$classname =~ s/\s$//;
$classname = fix_name ($classname);
$_ = <>;
while (<>) {
s/^\s*(.*)\s*$/\1/;
s/ /', '/;
s/\[(\w+)\]/', '\1/;
s/^(.*[^,])$/\1'/;
s/^/'/;
($type, $name, $arraylen) = split /\s*,\s*/;
$name =~ s/\s//g;
if (!$name) {
next;
}
if ($type =~ /^[a-zA-Z_']+$/) {
$type = fix_name ($type);
} else {
if ($actionscript_ints) {
$type =~ s/s32/vls32/;
$type =~ s/u32/vlu32/;
} else {
$type =~ s/s32/i/;
$type =~ s/u32/I/;
}
$type =~ s/u8/B/;
$type =~ s/u16/H/;
$type =~ s/s16/h/;
$type =~ s/d64/d/;
$type =~ s/u30/vlu30/;
}
if ($arraylen) {
push @lines, "($type, $name, $arraylen),";
} else {
push @lines, "($type, $name),";
}
}
print "class $classname (AVM2Unpackable):\n";
print "\t_struct = [\n";
foreach (@lines) {
print "\t\t$_\n";
}
print "\t]";
print "\n";