diff options
| author | ruki <[email protected]> | 2021-07-29 22:43:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-07-29 22:43:45 +0800 |
| commit | e2067d1b58aeec0024ac2f52e7599a4893b15f14 (patch) | |
| tree | 783e31fb7410f9e2eb17a47fbb6b7a6b1c09a74b /tests | |
| parent | 6acd768b2f692c49ddc89b5fffdfed0bf75744dc (diff) | |
impl vala rule
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/projects/vala/lua/src/main.vala | 21 | ||||
| -rw-r--r-- | tests/projects/vala/lua/src/sub/stub.vala | 21 | ||||
| -rw-r--r-- | tests/projects/vala/lua/xmake.lua | 10 | ||||
| -rw-r--r-- | tests/projects/vala/sdl/src/main.vala | 91 | ||||
| -rw-r--r-- | tests/projects/vala/sdl/xmake.lua | 5 |
5 files changed, 52 insertions, 96 deletions
diff --git a/tests/projects/vala/lua/src/main.vala b/tests/projects/vala/lua/src/main.vala new file mode 100644 index 000000000..8e8a32da0 --- /dev/null +++ b/tests/projects/vala/lua/src/main.vala @@ -0,0 +1,21 @@ +using Lua; + +static int my_func (LuaVM vm) { + stdout.printf ("Vala Code From Lua Code! (%f)\n", vm.to_number (1)); + return 1; +} + +static int main (string[] args) { + + string code = """ + print "Lua Code From Vala Code!" + my_func(33) + """; + + var vm = new LuaVM (); + vm.open_libs (); + vm.register ("my_func", my_func); + vm.do_string (code); + + return 0; +} diff --git a/tests/projects/vala/lua/src/sub/stub.vala b/tests/projects/vala/lua/src/sub/stub.vala new file mode 100644 index 000000000..7b3a2d4d8 --- /dev/null +++ b/tests/projects/vala/lua/src/sub/stub.vala @@ -0,0 +1,21 @@ +using Lua; + +static int my_func2 (LuaVM vm) { + stdout.printf ("Vala Code From Lua Code! (%f)\n", vm.to_number (1)); + return 1; +} + +static int main2 (string[] args) { + + string code = """ + print "Lua Code From Vala Code!" + my_func(33) + """; + + var vm = new LuaVM (); + vm.open_libs (); + vm.register ("my_func", my_func2); + vm.do_string (code); + + return 0; +} diff --git a/tests/projects/vala/lua/xmake.lua b/tests/projects/vala/lua/xmake.lua new file mode 100644 index 000000000..e149fb6d3 --- /dev/null +++ b/tests/projects/vala/lua/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.release", "mode.debug") + +add_requires("lua", "glib") + +target("test") + set_kind("binary") + add_rules("vala") + add_files("src/**.vala") + add_packages("lua", "glib") + add_values("vala.packages", "lua") diff --git a/tests/projects/vala/sdl/src/main.vala b/tests/projects/vala/sdl/src/main.vala deleted file mode 100644 index c8aa2588b..000000000 --- a/tests/projects/vala/sdl/src/main.vala +++ /dev/null @@ -1,91 +0,0 @@ -using SDL; -using SDLGraphics; - -public class SDLSample : Object { - - private const int SCREEN_WIDTH = 640; - private const int SCREEN_HEIGHT = 480; - private const int SCREEN_BPP = 32; - private const int DELAY = 10; - - private unowned SDL.Screen screen; - private GLib.Rand rand; - private bool done; - - public SDLSample () { - this.rand = new GLib.Rand (); - } - - public void run () { - init_video (); - - while (!done) { - draw (); - process_events (); - SDL.Timer.delay (DELAY); - } - } - - private void init_video () { - uint32 video_flags = SurfaceFlag.DOUBLEBUF - | SurfaceFlag.HWACCEL - | SurfaceFlag.HWSURFACE; - - this.screen = Screen.set_video_mode (SCREEN_WIDTH, SCREEN_HEIGHT, - SCREEN_BPP, video_flags); - if (this.screen == null) { - stderr.printf ("Could not set video mode.\n"); - } - - SDL.WindowManager.set_caption ("Vala SDL Demo", ""); - } - - private void draw () { - int16 x = (int16) rand.int_range (0, screen.w); - int16 y = (int16) rand.int_range (0, screen.h); - int16 radius = (int16) rand.int_range (0, 100); - uint32 color = rand.next_int (); - - Circle.fill_color (this.screen, x, y, radius, color); - Circle.outline_color_aa (this.screen, x, y, radius, color); - - this.screen.flip (); - } - - private void process_events () { - Event event; - while (Event.poll (out event) == 1) { - switch (event.type) { - case EventType.QUIT: - this.done = true; - break; - case EventType.KEYDOWN: - this.on_keyboard_event (event.key); - break; - } - } - } - - private void on_keyboard_event (KeyboardEvent event) { - if (is_alt_enter (event.keysym)) { - WindowManager.toggle_fullscreen (screen); - } - } - - private static bool is_alt_enter (Key key) { - return ((key.mod & KeyModifier.LALT)!=0) - && (key.sym == KeySymbol.RETURN - || key.sym == KeySymbol.KP_ENTER); - } - - public static int main (string[] args) { - SDL.init (InitFlag.VIDEO); - - var sample = new SDLSample (); - sample.run (); - - SDL.quit (); - - return 0; - } -} diff --git a/tests/projects/vala/sdl/xmake.lua b/tests/projects/vala/sdl/xmake.lua deleted file mode 100644 index 7f7266724..000000000 --- a/tests/projects/vala/sdl/xmake.lua +++ /dev/null @@ -1,5 +0,0 @@ -add_rules("mode.release", "mode.debug") - -target("test") - set_kind("binary") - add_files("src/*.vala") |
