From 2fffaffd15400ee42bd5bbf8f69f48b91f3513f8 Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Wed, 30 Nov 2022 14:16:36 +0000 Subject: [PATCH 1/6] Create target.mk Signed-off-by: Ian Hunter --- src/MATLAB/target.mk | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/MATLAB/target.mk diff --git a/src/MATLAB/target.mk b/src/MATLAB/target.mk new file mode 100644 index 000000000..c014d1f50 --- /dev/null +++ b/src/MATLAB/target.mk @@ -0,0 +1,3 @@ +.PHONY: matlab +matlab: all + octave src/MATLAB/main.m From 78d6356202bce0b78e262af9881ebd49a820d2eb Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Thu, 1 Dec 2022 19:06:50 +0000 Subject: [PATCH 2/6] matlab basics --- .github/workflows/test_language_bindings.yml | 12 ++++++++++++ src/MATLAB/main.m | 8 ++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/MATLAB/main.m diff --git a/.github/workflows/test_language_bindings.yml b/.github/workflows/test_language_bindings.yml index edd3c21e4..a7092b611 100644 --- a/.github/workflows/test_language_bindings.yml +++ b/.github/workflows/test_language_bindings.yml @@ -21,6 +21,7 @@ jobs: - test_java - test_javascript - test_julia + - test_matlab - test_perl - test_php - test_R @@ -147,6 +148,17 @@ jobs: - name: make julia run: make julia + test_matlab: + name: "Test: Matlab/Octave" + runs-on: ubuntu-latests + steps: + - uses: actions/checkout@v3 + - name: prereqs + run: sudo apt-get install octave -y + - name: run + run: make matlab + + test_perl: name: "Test: Perl" runs-on: ubuntu-latest diff --git a/src/MATLAB/main.m b/src/MATLAB/main.m new file mode 100644 index 000000000..15d7c27b8 --- /dev/null +++ b/src/MATLAB/main.m @@ -0,0 +1,8 @@ + +f = "output.dice" +delete(f) + +// roll_and_write("d20", f) + +data =textread(f,"%s") +print("Result: %s\n", data) \ No newline at end of file From 2821cb03c241fbec786e17868b0a02e042a553dc Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Fri, 2 Dec 2022 06:57:32 +0000 Subject: [PATCH 3/6] Update test_language_bindings.yml Signed-off-by: Ian Hunter --- .github/workflows/test_language_bindings.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_language_bindings.yml b/.github/workflows/test_language_bindings.yml index a7092b611..0ba20c649 100644 --- a/.github/workflows/test_language_bindings.yml +++ b/.github/workflows/test_language_bindings.yml @@ -150,7 +150,7 @@ jobs: test_matlab: name: "Test: Matlab/Octave" - runs-on: ubuntu-latests + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: prereqs From e3a8c60d579c75f1879fe5e44eceb756bc50b080 Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Sat, 17 Dec 2022 11:36:20 +0000 Subject: [PATCH 4/6] Update main.m Signed-off-by: Ian Hunter --- src/MATLAB/main.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MATLAB/main.m b/src/MATLAB/main.m index 15d7c27b8..9eeacb723 100644 --- a/src/MATLAB/main.m +++ b/src/MATLAB/main.m @@ -2,7 +2,7 @@ f = "output.dice" delete(f) -// roll_and_write("d20", f) +roll_and_write("d20", f) -data =textread(f,"%s") -print("Result: %s\n", data) \ No newline at end of file +data = textread(f,"%s") +print("Result: %s\n", data) From 09eec0f5abbecaa24601423429683c04d94c4804 Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Sat, 17 Dec 2022 11:38:33 +0000 Subject: [PATCH 5/6] Update target.mk Signed-off-by: Ian Hunter --- src/MATLAB/target.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MATLAB/target.mk b/src/MATLAB/target.mk index c014d1f50..430785fb8 100644 --- a/src/MATLAB/target.mk +++ b/src/MATLAB/target.mk @@ -1,3 +1,3 @@ .PHONY: matlab matlab: all - octave src/MATLAB/main.m + octave src/MATLAB/main.m build/libdice.so From 2a0193ed8b14c985513077a795a97f84df407a16 Mon Sep 17 00:00:00 2001 From: Ian Hunter Date: Mon, 27 Nov 2023 07:55:22 +0000 Subject: [PATCH 6/6] Update main.m Signed-off-by: Ian Hunter --- src/MATLAB/main.m | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/MATLAB/main.m b/src/MATLAB/main.m index 9eeacb723..09ac11175 100644 --- a/src/MATLAB/main.m +++ b/src/MATLAB/main.m @@ -1,8 +1,28 @@ +% Load the shared library +libraryPath = '../../build/libdice.so'; % Replace with the actual path to your library +lib = dlopen(libraryPath, 1); -f = "output.dice" -delete(f) +% Define the function signature +returnType = 'void'; +argTypes = {'char*', 'char*'}; +roll_and_write = libpointer('string', ''); -roll_and_write("d20", f) +% Call the function +[param1, param2] = deal('20d8', 'output.txt'); +calllib(lib, 'roll_and_write', roll_and_write, param1, param2); -data = textread(f,"%s") -print("Result: %s\n", data) +% Unload the library +dlclose(lib); + +% read result +outputFilePath = 'output.txt'; % Replace with the actual path to your output file +result = dlmread(outputFilePath); + +% Check if the result is greater than 1 +if result > 1 + disp('Result is greater than 1!'); + exit(0) +else + disp('Result is not greater than 1.'); +end +exit(1)