more examples
This commit is contained in:
parent
521c3c9bad
commit
d93b4d8dc6
|
@ -2,7 +2,7 @@
|
|||
|
||||
## What is _ztl_?
|
||||
|
||||
_ztl_ is an language transpiler with C/Zig/Rust/Lua/Fortran/Javascript/Elixir style syntax. The transpiler bootstrap is written in Lua which should make it easy to port to other systems.
|
||||
_ztl_ is an language transpiler with C/Zig/Rust style syntax. The transpiler bootstrap is written in Lua which should make it easy to port to other systems. _ztl_ also can "run" standalone inside of a lua vm for debugging purposes, it could be used for small scripting tasks or the like.
|
||||
|
||||
# _ztl_ Grammar and Specification
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
(set screen-height 450)
|
||||
(set username (get argv 1))
|
||||
(set password (get argv 2))
|
||||
(set me (make-player username (0.0 1.0 2.0) PURPLE))
|
||||
(set me (make :player username (0.0 1.0 2.0) PURPLE))
|
||||
(set players (login me))
|
||||
(set camera (make-camera (me.pos.x, me.pos.y + 10.0, me.pos.z + 10.0)
|
||||
(me.pos.x, me.pos.y, me.pos.z)
|
||||
(0.0, 1.0, 0.0)
|
||||
(set camera (make :camera (me.pos.x (add me.pos.y 10.0) (add me.pos.z 10.0))
|
||||
(me.pos.x me.pos.y me.pos.z)
|
||||
(0.0 1.0 0.0)
|
||||
45.0
|
||||
CAMERA-PERSPECTIVE))
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
(* do the login here *)
|
||||
} fn
|
||||
|
||||
255 255 0 :purple color
|
||||
(255 255 0) :purple color
|
||||
|
||||
:main {
|
||||
800 :screen_width i32
|
||||
|
@ -72,7 +72,8 @@
|
|||
|
||||
camera me sync_camera
|
||||
|
||||
player_updated choose {
|
||||
player_updated
|
||||
choose {
|
||||
me move :players set
|
||||
} ifyes {
|
||||
me ping :players set
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
type :Vec {
|
||||
f32 :x,
|
||||
f32 :y,
|
||||
f32 :z,
|
||||
};
|
||||
|
||||
type :Color {
|
||||
i8 :r,
|
||||
i8 :g,
|
||||
i8 :b,
|
||||
};
|
||||
|
||||
type :Player {
|
||||
str :username,
|
||||
Vec :pos,
|
||||
Color :color,
|
||||
};
|
||||
|
||||
fn :login (Player str -> bool) {
|
||||
set p to pop; /* getting the player from the stack */
|
||||
set password to pop; /* get the string from the stack */
|
||||
|
||||
return true; /* return back from function and push value on stack */
|
||||
};
|
||||
|
||||
Color :purple {255 255 0};
|
||||
|
||||
fn :main (i32 str[] -> i32) {
|
||||
set :argc to pop; // to is a noop but makes it more readable
|
||||
set :argv to pop;
|
||||
|
||||
set :screen_width to i32 800;
|
||||
set :screen_height to i32 450;
|
||||
|
||||
set :username to argv[0];
|
||||
set :password to argv[1];
|
||||
|
||||
set :me to Player { // the brackets are for readablity, the ';' is neccisarry
|
||||
username,
|
||||
vec {0.0 1.0 2.0},
|
||||
purple,
|
||||
};
|
||||
|
||||
set :players to Player[] { login me password; };
|
||||
|
||||
set :camera to Camera3D {
|
||||
vec {0.0 1.0 0.0},
|
||||
i32 45.0,
|
||||
atom :CAMERA_PERSPECTIVE,
|
||||
vec {
|
||||
add me.pos.x 10.0,
|
||||
add me.pos.y 10.0,
|
||||
me.pos.z,
|
||||
},
|
||||
me.pos,
|
||||
};
|
||||
|
||||
init_window "zwl client : raylib" screen_width screen_height;
|
||||
set_target_fps 60;
|
||||
|
||||
(* Main game loop *)
|
||||
while ( not window_should_close ) {
|
||||
|
||||
if (is_key_down :KEY_RIGHT) {
|
||||
set me.pos.x to {add me.pos.x 0.2};
|
||||
set :player_updated true;
|
||||
}
|
||||
|
||||
if (is_key_down :KEY_LEFT) {
|
||||
set me.pos.x to {sub me.pos.x 0.2};
|
||||
set :player_updated true;
|
||||
}
|
||||
|
||||
if (is_key_down :KEY_DOWN) {
|
||||
set me.pos.z to {add me.pos.z 0.2};
|
||||
set :player_updated true;
|
||||
}
|
||||
|
||||
if (is_key_down :KEY_UP) {
|
||||
set me.pos.z to {sub me.pos.z 0.2};
|
||||
set :player_updated true;
|
||||
}
|
||||
|
||||
sync_camera camera me;
|
||||
|
||||
if (player_updated) {
|
||||
set :players move me;
|
||||
} else {
|
||||
set :players ping me;
|
||||
}
|
||||
|
||||
begin_drawing;
|
||||
clear_background RAYWHITE;
|
||||
|
||||
begin_mode_3d camera;
|
||||
|
||||
(* Draw floor *)
|
||||
draw_grid 30 1.0;
|
||||
|
||||
draw_cube me.pos 0.5 0.5 0.5 me.apperance;
|
||||
|
||||
map :player players {
|
||||
draw_cube player.pos 0.5 0.5 0.5 player.apperance;
|
||||
}
|
||||
|
||||
end_mode_3d;
|
||||
|
||||
end_drawing;
|
||||
}
|
||||
/* Detect window close button or ESC key */
|
||||
|
||||
set :players to logout me;
|
||||
close_window; /*Close window and OpenGL context */
|
||||
}
|
||||
|
||||
main;
|
|
@ -0,0 +1,100 @@
|
|||
use "common.ztl"
|
||||
|
||||
fn :login (9p, Player, str -> []Player) {
|
||||
set s to pop;
|
||||
set p to pop;
|
||||
set password to pop;
|
||||
|
||||
s.auth(p.username, password);
|
||||
return s.read("players");
|
||||
};
|
||||
|
||||
fn :main (i32 str[] -> i32) {
|
||||
set :argc to pop;
|
||||
set :argv to pop;
|
||||
|
||||
set :screen_width to i32 800;
|
||||
set :screen_height to i32 450;
|
||||
|
||||
set :username to argv[0];
|
||||
set :password to argv[1];
|
||||
|
||||
set :me to Player {
|
||||
username,
|
||||
vec {0.0 1.0 2.0},
|
||||
purple,
|
||||
};
|
||||
|
||||
set :players to Player[] { login me password; };
|
||||
|
||||
set :camera to Camera3D {
|
||||
vec {0.0 1.0 0.0},
|
||||
i32 45.0,
|
||||
atom :CAMERA_PERSPECTIVE,
|
||||
vec {
|
||||
add me.pos.x 10.0,
|
||||
add me.pos.y 10.0,
|
||||
me.pos.z,
|
||||
},
|
||||
me.pos,
|
||||
};
|
||||
|
||||
init_window "zwl client : raylib" screen_width screen_height;
|
||||
set_target_fps 60;
|
||||
|
||||
(* Main game loop *)
|
||||
while ( not window_should_close ) {
|
||||
|
||||
if (is_key_down :KEY_RIGHT) {
|
||||
set me.pos.x to {add me.pos.x 0.2};
|
||||
set :player_updated true;
|
||||
}
|
||||
|
||||
if (is_key_down :KEY_LEFT) {
|
||||
set me.pos.x to {sub me.pos.x 0.2};
|
||||
set :player_updated true;
|
||||
}
|
||||
|
||||
if (is_key_down :KEY_DOWN) {
|
||||
set me.pos.z to {add me.pos.z 0.2};
|
||||
set :player_updated true;
|
||||
}
|
||||
|
||||
if (is_key_down :KEY_UP) {
|
||||
set me.pos.z to {sub me.pos.z 0.2};
|
||||
set :player_updated true;
|
||||
}
|
||||
|
||||
sync_camera camera me;
|
||||
|
||||
if (player_updated) {
|
||||
set :players move me;
|
||||
} else {
|
||||
set :players ping me;
|
||||
}
|
||||
|
||||
begin_drawing;
|
||||
clear_background RAYWHITE;
|
||||
|
||||
begin_mode_3d camera;
|
||||
|
||||
(* Draw floor *)
|
||||
draw_grid 30 1.0;
|
||||
|
||||
draw_cube me.pos 0.5 0.5 0.5 me.apperance;
|
||||
|
||||
map :player players {
|
||||
draw_cube player.pos 0.5 0.5 0.5 player.apperance;
|
||||
}
|
||||
|
||||
end_mode_3d;
|
||||
|
||||
end_drawing;
|
||||
}
|
||||
/* Detect window close button or ESC key */
|
||||
|
||||
set :players to logout me;
|
||||
close_window; /*Close window and OpenGL context */
|
||||
};
|
||||
|
||||
main;
|
|
@ -0,0 +1,19 @@
|
|||
type :Vec {
|
||||
f32 :x,
|
||||
f32 :y,
|
||||
f32 :z,
|
||||
};
|
||||
|
||||
type :Color {
|
||||
i8 :r,
|
||||
i8 :g,
|
||||
i8 :b,
|
||||
};
|
||||
|
||||
type :Player {
|
||||
str :username,
|
||||
Vec :pos,
|
||||
Color :color,
|
||||
};
|
||||
|
||||
Color :purple {255 255 0};
|
|
@ -0,0 +1,63 @@
|
|||
use "common.ztl"
|
||||
|
||||
fn :main(i32, []str -> i32) {
|
||||
set :argc to pop;
|
||||
set :argv to pop;
|
||||
|
||||
set s to tunnel "0.0.0.0:25565";
|
||||
s.host (
|
||||
version,
|
||||
auth,
|
||||
error,
|
||||
flush,
|
||||
attach,
|
||||
walk,
|
||||
open,
|
||||
create,
|
||||
read,
|
||||
write,
|
||||
clunk,
|
||||
remove,
|
||||
stat,
|
||||
);
|
||||
}
|
||||
|
||||
fn :version(9pmsg) {
|
||||
|
||||
}
|
||||
fn :auth(9pmsg) {
|
||||
|
||||
}
|
||||
fn :error(9pmsg) {
|
||||
|
||||
}
|
||||
fn :flush(9pmsg) {
|
||||
|
||||
}
|
||||
fn :attach(9pmsg) {
|
||||
|
||||
}
|
||||
fn :walk(9pmsg) {
|
||||
|
||||
}
|
||||
fn :open(9pmsg) {
|
||||
|
||||
}
|
||||
fn :create(9pmsg) {
|
||||
|
||||
}
|
||||
fn :read(9pmsg) {
|
||||
|
||||
}
|
||||
fn :write(9pmsg) {
|
||||
|
||||
}
|
||||
fn :clunk(9pmsg) {
|
||||
|
||||
}
|
||||
fn :remove(9pmsg) {
|
||||
|
||||
}
|
||||
fn :stat(9pmsg) {
|
||||
|
||||
}
|
Loading…
Reference in New Issue