-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create main.r Signed-off-by: Ian Hunter <[email protected]> * Create test_R.yml Signed-off-by: Ian Hunter <[email protected]> * Create target.mk Signed-off-by: Ian Hunter <[email protected]> * Update target.mk Signed-off-by: Ian Hunter <[email protected]> * Update Makefile Signed-off-by: Ian Hunter <[email protected]> * Update test_R.yml Signed-off-by: Ian Hunter <[email protected]> * Update test_R.yml Signed-off-by: Ian Hunter <[email protected]> * Update test_R.yml Signed-off-by: Ian Hunter <[email protected]> * Update test_R.yml Signed-off-by: Ian Hunter <[email protected]> * Update test_R.yml Signed-off-by: Ian Hunter <[email protected]> * Update target.mk Signed-off-by: Ian Hunter <[email protected]> * Update target.mk Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update target.mk Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update target.mk Signed-off-by: Ian Hunter <[email protected]> * Update target.mk Signed-off-by: Ian Hunter <[email protected]> * Update target.mk Signed-off-by: Ian Hunter <[email protected]> * Update target.mk Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update shared_header.h Signed-off-by: Ian Hunter <[email protected]> * Update dice.yacc Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * Update main.r Signed-off-by: Ian Hunter <[email protected]> * working R * update readmes Signed-off-by: Ian Hunter <[email protected]>
- Loading branch information
1 parent
76a44dd
commit dd486b7
Showing
10 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: "Test: R" | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: r-lib/actions/setup-r@v2 | ||
- name: make r | ||
run: make r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,4 +156,7 @@ src/go/main | |
*.stackdump | ||
|
||
# TROLL | ||
test.t | ||
test.t | ||
|
||
# GNOLL Outputs | ||
*.dice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# R Support | ||
|
||
## Setup | ||
Generate the shared object file that R can consume. | ||
```bash | ||
make r | ||
``` | ||
|
||
Inside `main.r` we show an example of GNOLL usage. | ||
|
||
- Load in the shared object | ||
- Delete the temporary file that contains GNOLL output | ||
- Call GNOLL | ||
- Parse result | ||
|
||
## Notes | ||
This example uses the .C function which is usually not recommended. The recommended way to call C code in R is through the .Call() function. See [#368](https://github.com/ianfhunter/GNOLL/issues/368) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# print("Hello GNOLL") | ||
|
||
dyn.load("build/r/dice.so") | ||
|
||
fn = "output.dice" | ||
if(file.exists(fn)){ | ||
file.remove(fn) | ||
} | ||
|
||
return_code = as.integer(-1) | ||
error_code = .C( | ||
"roll_and_write_R", | ||
value=return_code, | ||
"1d20", | ||
fn | ||
) | ||
|
||
if(error_code$value != 0){ | ||
print(paste("GNOLL Error Code:", error_code$value)) | ||
stop("GNOLL Exit code was not Success") | ||
} | ||
|
||
result <- readLines(fn, warn=FALSE) | ||
tokens <- strsplit(result, ";") | ||
int_tokens <- strtoi(tokens) | ||
|
||
print(paste("GNOLL rolled:", result)) | ||
|
||
if(int_tokens[1] <= 0 | int_tokens[1] > 20){ | ||
stop ("GNOLL rolled invalid value") | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.PHONY: r | ||
|
||
r: clean yacc lex compile $(OBJECTS) | ||
mkdir -p build/r/ | ||
$(CC) -shared -o build/r/dice.so $(OBJECTS) $(ARC4RANDOM) -lR | ||
Rscript src/R/main.r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters