Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

add working helloworld #40

Merged
merged 6 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ bindgen.txt
src/bindings.rs
creduce_bug_*
# !__bindgen.ii
*.log
*.log
*.oct
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 5 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
[package]
name = "octh"
version = "0.1.0"
authors = ["Cameron Taggart <[email protected]>"]
build = "build.rs"
description = "A bindgen generated Rust wrapper around oct.h for creating Oct-Files for GNU Octave"
keywords = ["Octave"]
license = "GPL"
homepage = "https://github.com/ctaggart/octh"
repository = "https://github.com/ctaggart/octh"
edition = "2018"

[lib]
# crate-type = ["dylib"]

[build-dependencies]
# bindgen = "*"
# need https://github.com/rust-lang/rust-bindgen/commit/fa6a68d7c768cd9d4efc418f5d8d9ceb104704ad
bindgen = { branch = "master", git = "https://github.com/rust-lang/rust-bindgen" }
cc = "*"
[workspace]
members = [
"octh",
"example-helloworld",
]
3 changes: 0 additions & 3 deletions build.ps1

This file was deleted.

10 changes: 10 additions & 0 deletions example-helloworld/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "helloworld"
version = "0.1.0"
edition = "2018"

[lib]
crate-type = ["cdylib"]

[dependencies]
octh = { path = "../octh" }
5 changes: 5 additions & 0 deletions example-helloworld/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
println!("/home/linuxbrew/.linuxbrew/Cellar/octave/5.1.0_6/lib/octave/5.1.0");
println!("cargo:rustc-link-lib=octave");
println!("cargo:rustc-link-lib=octinterp");
}
37 changes: 37 additions & 0 deletions example-helloworld/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
The is a port of the `helloworld.cc` from [A.1.1 Getting Started with Oct-File](https://octave.org/doc/interpreter/Getting-Started-with-Oct_002dFiles.html#Getting-Started-with-Oct_002dFiles). The original ported C++ was:

``` cc
#include <octave/oct.h>

DEFUN_DLD (helloworld, args, nargout,
"Hello World Help String")
{
octave_stdout << "Hello World has "
<< args.length () << " input arguments and "
<< nargout << " output arguments.\n";

// Return empty matrices for any outputs
octave_value_list retval (nargout);
for (int i = 0; i < nargout; i++)
retval(i) = octave_value (Matrix ());

return retval;
}
```

The `mkoctfile` function compiles it to a `helloworld.oct` file. You can then run it within Octave with:
``` m
helloworld (1, 2, 3)
```
Which prints:
```
Hello World has 3 input arguments and 0 output arguments.
```

You can build this example by doing:
``` sh
cargo build
cp target/debug/libhelloworld.so helloworld.oct
```

Start Octave with `octave`. Then run `helloworld (1, 2, 3)` within Octave.
14 changes: 14 additions & 0 deletions example-helloworld/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use octh::*;

#[no_mangle]
pub extern "C" fn Ghelloworld (library: *const dynamic_library, relative: bool) -> *mut dld_function {
let name = StdString::from_bytes_with_nul(b"helloworld\0");
let help = StdString::from_bytes_with_nul(b"Hello World Help String\0");
dld_function_create(helloworld, library, name, help, relative)
}

extern "C" fn helloworld (args: *const value_list, nargout: i32) -> value_list {
let nargin = value_list_length(args);
println!("Hello World has {} input arguments and {} output arguments.", nargin, nargout);
value_list_new(0)
}
23 changes: 0 additions & 23 deletions issue/octh15.sh

This file was deleted.

File renamed without changes.
20 changes: 20 additions & 0 deletions octh/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "octh"
version = "0.1.0"
authors = ["Cameron Taggart <[email protected]>"]
build = "build.rs"
description = "A bindgen generated Rust wrapper around oct.h for creating Oct-Files for GNU Octave"
keywords = ["Octave"]
license = "GPL"
homepage = "https://github.com/ctaggart/octh"
repository = "https://github.com/ctaggart/octh"
edition = "2018"

[lib]
# crate-type = ["dylib"]

[build-dependencies]
# bindgen = "*"
# need https://github.com/rust-lang/rust-bindgen/commit/fa6a68d7c768cd9d4efc418f5d8d9ceb104704ad
bindgen = { branch = "master", git = "https://github.com/rust-lang/rust-bindgen" }
cc = "*"
1 change: 1 addition & 0 deletions build.rs → octh/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn bindgen(target: &str) {
.enable_cxx_namespaces()
.whitelist_type("octave.*")
.whitelist_function("octave.*")
.whitelist_function("stdstring.*")
.opaque_type("octave.refcount")
.use_core()
// .raw_line("#![allow(warnings)]")
Expand Down
Loading