Browse Source

rust bindings

tags/v4
parent
commit
b70ec4ddce
Signed by: govanify GPG Key ID: DE62E1E2A6145556
10 changed files with 67 additions and 1 deletions
  1. +2
    -0
      .gitignore
  2. +3
    -1
      bindings/csharp/Program.cs
  3. +1
    -0
      bindings/csharp/README.md
  4. +1
    -0
      bindings/python/README.md
  5. +2
    -0
      bindings/python/example.py
  6. +10
    -0
      bindings/rust/Cargo.toml
  7. +5
    -0
      bindings/rust/README.md
  8. +7
    -0
      bindings/rust/build.rs
  9. +34
    -0
      bindings/rust/src/main.rs
  10. +2
    -0
      utils/default.nix

+ 2
- 0
.gitignore View File

@@ -10,3 +10,5 @@ release.zip
build/
bin/
obj/
target/
Cargo.lock

+ 3
- 1
bindings/csharp/Program.cs View File

@@ -29,7 +29,6 @@ namespace csharp
[DllImport(libipc)]
static extern UInt32 GetError(IntPtr v);


static void Main(string[] args)
{
// we get our ipc object
@@ -41,6 +40,9 @@ namespace csharp
// we check for errors
Console.WriteLine("Error (if any): {0}", GetError(ipc));

// we delete the object and free the resources
deletePCSX2Ipc(ipc);

// for more infos check out the C bindings documentation :D !
}
}


+ 1
- 0
bindings/csharp/README.md View File

@@ -2,3 +2,4 @@ C# bindings for the IPC lib.

This requires you to build the C library for your OS first.
Refer to `bindings/c` for that.
Once done make sure the library is in your build and/or execution folders.

+ 1
- 0
bindings/python/README.md View File

@@ -2,3 +2,4 @@ Python bindings for the IPC lib.

This requires you to build the C library for your OS first.
Refer to `bindings/c` for that.
Once done make sure the library is in your build and/or execution folders.

+ 2
- 0
bindings/python/example.py View File

@@ -27,5 +27,7 @@ print(libipc.Read(ipc, 0x00347D34, 0, False))
# we check for errors
print("Error (if any): " + str(libipc.GetError(ipc)))

# we delete the object and free the resources
libipc.deletePCSX2Ipc(ipc)

# for more infos check out the C bindings documentation :D !

+ 10
- 0
bindings/rust/Cargo.toml View File

@@ -0,0 +1,10 @@
[package]
name = "rust"
version = "0.1.0"
authors = ["Gauvain 'GovanifY' Roussel-Tarbouriech <gauvain@govanify.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libc = "*"

+ 5
- 0
bindings/rust/README.md View File

@@ -0,0 +1,5 @@
Rust bindings for the IPC lib.

This requires you to build the C library for your OS first.
Refer to `bindings/c` for that.
Once done make sure the library is in your build and/or execution folders.

+ 7
- 0
bindings/rust/build.rs View File

@@ -0,0 +1,7 @@
use std::path::Path;
use std::env;

fn main() {
let dir = env::current_dir().unwrap();
println!("cargo:rustc-link-search=native={}", Path::new(&dir).display());
}

+ 34
- 0
bindings/rust/src/main.rs View File

@@ -0,0 +1,34 @@
extern crate libc;
use libc::{c_char, c_uint, c_ulong};

#[repr(C)] pub struct PCSX2Ipc { _private: [u8; 0] }

#[link(name = "pcsx2_ipc_c")]
extern "C" {
/* I defined the functions I wanted to use for the example
* below but if you need other ones you'll have to
* define them here, it's not too hard, just be sure
* to look up Rust FFI documentation. */
fn newPCSX2Ipc() -> *mut PCSX2Ipc;
fn Read(v: *mut PCSX2Ipc, address: c_uint, msg: c_char, batch: bool) -> c_ulong;
fn deletePCSX2Ipc(v: *mut PCSX2Ipc);
fn GetError(v: *mut PCSX2Ipc) -> c_uint;

}
fn main() {
unsafe {
// we get our ipc object
let _ipc = newPCSX2Ipc();

// we read an uint8_t from memory location 0x00347D34
println!("{}", Read(_ipc, 0x00347D34, 0x00, false));

// we check for errors
println!("Error (if any): {}", GetError(_ipc));

// we delete the object and free the resources
deletePCSX2Ipc(_ipc);
// for more infos check out the C bindings documentation :D !
}
}

+ 2
- 0
utils/default.nix View File

@@ -14,9 +14,11 @@ pkgs.mkShell {
newunicodechar etoc; })
pkgs.dotnet-sdk_3
pkgs.pythonPackages.pip
pkgs.cargo
];
# clang is pretty nice
shellHook = ''
export CXX="clang++"
export CARGO_HOME=$HOME/.cache/cargo
'';
}

Loading…
Cancel
Save