Skip to content

Commit d991a98

Browse files
bruter updated to 0.2.7f
1 parent f147ada commit d991a98

File tree

5 files changed

+399
-92
lines changed

5 files changed

+399
-92
lines changed

bruter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Lua(5.1+) and Terra compatible;
3333

3434
- `boolean` = args that are true or false
3535

36-
- `string` = args delimited by backticks(`) or keys({}) and anything else that doesnt match the other types
36+
- `string` = args delimited by backticks(`) or curly brackets({}) and anything else that doesnt match the other types
3737

3838
- `sentence` = code that is enclosed by parenthesis, it is executed in order then the result is put in place of the sentence.
3939

bruter/example/benchmark.br

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
set mapSize 16;
2+
set random $utils.random;
3+
4+
set global.br $this;
5+
6+
set Vector2 from function {x y}
7+
{
8+
return (obj x $x y $y);
9+
};
10+
11+
lua.eval {br.push = function(t, v) table.insert(t, v) end};
12+
13+
set roomMaxSize (Vector2 32 32);
14+
set roomAmount 128;
15+
16+
set Creature from function {name position}
17+
{
18+
set tempcreature (obj name $name position $position);
19+
set tempcreature.globalPosition 1;
20+
set tempcreature.needs (obj hunger 100 thirst 100 health 100);
21+
set tempcreature.stats (obj strength 10 dexterity 10 intelligence 10);
22+
set tempcreature.inventory [];
23+
set tempcreature.equipment (obj head nil body nil legs nil hands nil feet nil);
24+
set tempcreature.room 1;
25+
return $tempcreature;
26+
};
27+
28+
set Room from function {w h}
29+
{
30+
set temproom (obj w $w h $h);
31+
set temproom.map (utils.matrix.new $w $h 46);
32+
33+
set iy (random 2 (- $h 2));
34+
set oy (random 2 (- $h 2));
35+
set ix (random 2 (- $w 2));
36+
set ox (random 2 (- $w 2));
37+
38+
set tmpw (- $w 1);
39+
set tmph (- $h 1);
40+
// create the walls on the limits
41+
//print $w $h;
42+
for {set i 1} {< $i $w} {set i (+ $i 1)}
43+
{
44+
//print $i;
45+
set temproom.map.$i.1 35;
46+
set temproom.map.$i.$tmph 35;
47+
};
48+
49+
for {set i 1} {< $i $h} {set i (+ $i 1)}
50+
{
51+
set temproom.map.1.$i 35;
52+
set temproom.map.$tmpw.$i 35;
53+
};
54+
55+
set doorbyte 32;
56+
57+
set tmpx (random 2 (- $w 2));
58+
set temproom.map.$tmpx.1 $doorbyte;
59+
set tmpx (random 2 (- $w 2));
60+
set tmph (- $h 1);
61+
set temproom.map.$tmpx.$tmph $doorbyte;
62+
set tmpx nil;
63+
set tmph nil;
64+
set tmpy (random 2 (- $h 2));
65+
set temproom.map.1.$tmpy $doorbyte;
66+
set tmpy (random 2 (- $h 2));
67+
set tmpw (- $w 1);
68+
set temproom.map.$tmpw.$tmpy $doorbyte;
69+
set tmpy nil;
70+
set tmpw nil;
71+
72+
return $temproom;
73+
};
74+
75+
set genRooms from function {}
76+
{
77+
set rooms from [];
78+
for {set x 1} {< $x (/ $roomAmount 2)} {set x (+ $x 1)}
79+
{
80+
set rooms.$x from [];
81+
for {set y 1} {< $y (/ $roomAmount 2)} {set y (+ $y 1)}
82+
{
83+
set rooms.$x.$y (Room (random 7 $roomMaxSize.x) (random 7 $roomMaxSize.y ));
84+
};
85+
};
86+
return $rooms;
87+
};
88+
89+
set world from [];
90+
set world.rooms (genRooms);
91+
set world.creatures ([]);
92+
set tmpx (random 5 (len $world.rooms.1));
93+
set tmpy (random 5 (len $world.rooms));
94+
push $world.creatures (Creature `player` (Vector2 (random 5 $tmpx ) (random 5 $tmpy)));
95+
set player $world.creatures.1;
96+
lua.eval {br["rawprint"] = io.write;};
97+
98+
set printmaptile from function {_map _x _y}
99+
{
100+
lua.eval (string `io.write("" .. string.char(br._map[` $_x `][` $_y `]));`);
101+
};
102+
103+
lua.eval {br["io"] = io};
104+
105+
set printroom from function {_map}
106+
{
107+
for {set i 1} {< $i (len $_map.1)} {set i (+ $i 1)}
108+
{
109+
for {set j 1} {< $j (len $_map)} {set j (+ $j 1)}
110+
{
111+
if {and (== $j $player.position.x) (== $i $player.position.y)}
112+
{
113+
io.write {@};
114+
}
115+
else
116+
{
117+
printmaptile $_map $j $i;
118+
};
119+
};
120+
print {};
121+
};
122+
};
123+
124+
printroom $world.rooms.1.1.map;

bruter/example/loop.br

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
vm.safe;
2-
3-
lua.eval "print('Hello from Lua!')";
2+
lua.eval "print('Hello from Lua!')"; -- not gonna work because of vm.safe;
43

54
set a 45;
65
set b 5;
@@ -25,17 +24,22 @@ for {set i 0} {< $i 10} {set i (+ $i 1)}
2524
};
2625
};
2726

28-
for value in $c
27+
each value in $c
2928
{
3029
print value = $value;
3130
};
3231

33-
for name value in $c
32+
each name value in $c
3433
{
3534
print name = $name;
3635
print value = $value;
3736
};
3837

38+
for {set i 0} {< $i 10} {set i (+ $i 1)}
39+
{
40+
// print i = $i;
41+
};
42+
3943
print $i;
4044
print $a;
4145
print $b;

bruter/lib/luatils/_string.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,8 @@ _string.trim = function(s)
167167
return s:gsub("^%s+", ""):gsub("%s+$", "")
168168
end
169169

170+
_string.firstWord = function(str)
171+
return str:match("%S+") or ""
172+
end
173+
170174
return _string

0 commit comments

Comments
 (0)