summaryrefslogtreecommitdiff
path: root/tests/projects
diff options
context:
space:
mode:
authorruki <[email protected]>2021-07-29 12:04:08 +0800
committerGitHub <[email protected]>2021-07-29 12:04:08 +0800
commit9776c89aec960c73bc1fd7c47ef61a54de2ba4ef (patch)
tree63880515f449a33b05484d67b7fbd95995458429 /tests/projects
parent309343f78d84dcf654019b1b84756a659e8c2649 (diff)
parent10a61c13f734a0a813d2e8d38eba42c823f407f0 (diff)
Merge pull request #1538 from xmake-io/vala
add vala language support
Diffstat (limited to 'tests/projects')
-rw-r--r--tests/projects/vala/lua/src/main.vala21
-rw-r--r--tests/projects/vala/lua/xmake.lua10
-rw-r--r--tests/projects/vala/sdl/main.vala91
3 files changed, 31 insertions, 91 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/xmake.lua b/tests/projects/vala/lua/xmake.lua
new file mode 100644
index 000000000..df0cbeb89
--- /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/main.vala b/tests/projects/vala/sdl/main.vala
deleted file mode 100644
index c8aa2588b..000000000
--- a/tests/projects/vala/sdl/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;
- }
-}