Skip to content

Commit

Permalink
Split up the files a bit, update fern
Browse files Browse the repository at this point in the history
  • Loading branch information
bmisiak committed Jul 29, 2022
1 parent 725a2c6 commit 19aabab
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 163 deletions.
58 changes: 21 additions & 37 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,21 @@ jobs:
override: true
- uses: actions-rs/cargo@v1
with:
use-cross: true
use-cross: true # cross uses glibc 2.15
command: build
args: --target i686-unknown-linux-gnu --release
- name: Create Linux release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false
- name: Upload Linux Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: upload-linux-release
uses: ncipollo/release-action@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./target/i686-unknown-linux-gnu/release/libnfg_timer.so
asset_name: samp-precise-timers.so
asset_content_type: application/x-sharedlib
artifacts: ./target/i686-unknown-linux-gnu/release/libsamp_precise_timers.so
replacesArtifacts: false
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
draft: true
omitBody: true
tag: ${{ github.ref }}
commit: ${{ github.ref }}
build-windows:
runs-on: windows-latest
strategy:
Expand All @@ -60,23 +52,15 @@ jobs:
- uses: actions/checkout@v2
- name: Build for Windows
run: rustup target add i686-pc-windows-msvc && cargo build --release --target i686-pc-windows-msvc
- name: Create Windows release
id: create_release_windows
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false
- name: Upload Windows Release Asset
id: upload-release-asset-windows
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: upload-windows-release
uses: ncipollo/release-action@v1
with:
upload_url: ${{ steps.create_release_windows.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: .\target\i686-pc-windows-msvc\release\nfg_timer.dll
asset_name: samp-precise-timers.dll
asset_content_type: application/octet-stream
artifacts: .\target\i686-pc-windows-msvc\release\samp_precise_timers.dll
replacesArtifacts: false
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
draft: true
omitBody: true
tag: ${{ github.ref }}
commit: ${{ github.ref }}
78 changes: 68 additions & 10 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "nfg-timer"
name = "samp-precise-timers"
version = "1.0.0"
authors = ["Brian Misiak <[email protected]>"]
edition = "2018"
Expand All @@ -14,7 +14,7 @@ crate-type = ["cdylib"]
samp = { git = "https://github.com/ZOTTCE/samp-rs.git", rev = "2e9192713bf9a77ee04e0ebbcda37d078c9c47dd" }
slab = "0.4.2"
log = "0.4.6"
fern = "0.5.7"
fern = "0.5.9"

[profile.release]
lto = true
lto = true
49 changes: 49 additions & 0 deletions src/amx_arguments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use log::error;
use std::convert::TryFrom;
use samp::prelude::AmxString;

/// These are the types of arguments the plugin supports for passing on to the callback.
#[derive(Debug, Clone)]
pub enum PassedArgument {
PrimitiveCell(i32),
Str(Vec<u8>),
Array(Vec<i32>),
}

/// Consumes variadic PAWN params into Vec<PassedArgument>
/// It expects the first of args to be a string of type letters, i.e. "dds",
/// which instruct us how to interpret the following arguments.
pub fn parse_variadic_arguments_passed_into_timer(
mut args: samp::args::Args,
) -> Option<Vec<PassedArgument>> {
let argument_type_letters = args.next::<AmxString>()?.to_bytes();
if argument_type_letters.len() != args.count() - 4 {
error!("The amount of callback arguments passed ({}) does not match the length of the list of types ({}).",args.count() - 4, argument_type_letters.len());
return None;
}

let mut collected_arguments: Vec<PassedArgument> = Vec::with_capacity(argument_type_letters.len());
let mut argument_type_letters = argument_type_letters.iter();

while let Some(type_letter) = argument_type_letters.next() {
collected_arguments.push(
match type_letter {
b's' => PassedArgument::Str( args.next::<AmxString>()?.to_bytes() ),
b'a' => {
if let Some(b'i') | Some(b'A') = argument_type_letters.next() {
let array_argument: samp::cell::UnsizedBuffer = args.next()?;
let length_argument = args.next::<i32>().and_then(|len| usize::try_from(len).ok())?;
let amx_buffer = array_argument.into_sized_buffer(length_argument);

PassedArgument::Array( amx_buffer.as_slice().to_vec() )
} else {
error!("Array arguments (a) must be followed by an array length argument (i/A).");
return None;
}
},
_ => PassedArgument::PrimitiveCell( args.next::<i32>()? )
}
);
}
Some(collected_arguments)
}
Loading

0 comments on commit 19aabab

Please sign in to comment.