SA-MP Forums Archive
[Tool/Web/Other] Rust SA:MP SDK - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: [Tool/Web/Other] Rust SA:MP SDK (/showthread.php?tid=651131)



Rust SA:MP SDK - EvaBaka - 14.03.2018

It's a Rust library allows you to write plugins in Rust.

Features
Hides most of type coercion. You don't need make a cell type as a String or other things yourself.

Macros: Make a new plugin
Code:
struct Plugin {
    version: &'static str,
    amx_count: u32,
}

impl Plugin {
    fn load(&self) -> bool {
        log!("Plugin is loaded. Version: {}", self.version);
        return true;
    }

    fn amx_load(&mut self, amx: &AMX) -> Cell {
        let natives = natives![
            { "MyFunction", my_function }
        ];

        match amx.register(natives) {
            Ok(_) => log!("Natives are successful loaded"),
            Err(err) => log!("Whoops, there is an error {:?}", err),
        }

        self.amx_count += 1;

        AMX_ERR_NONE
    }

    fn amx_unload(&mut self, _: &AMX) -> Cell {
        self.amx_count -= 1;

        AMX_ERR_NONE
    }

    fn my_function(&self, _amx: &AMX, player_id: i32) -> AmxResult<Cell> {
        Ok(-player_id)
    }
}

impl Default for Plugin {
    fn default() -> Self {
        Plugin {
            version: "0.1",
            amx_count: 0,
        }
    }
}

new_plugin!(Plugin);

// Also you can make a plugin with ProcessTick support.
new_plugin!(Plugin with process_tick)
Define a native function.
Hides arguments parsing inside the macro.

All you need are to define a method function_name in your new plugin with given arguments.

Code:
// native: FunctionName(int_arg, &float_arg);
define_native!(function_name, int_arg: i32, float_ref_arg: ref f32);

// native: WithoutArguments();
define_native(function_name);
Call natives and public functions.
Code:
// Broadcast to all subscribers that a user have changed his name.
fn notify(&self, amx: AMX, player_id: u32, old_name: String, new_name: String) -> AmxResult<Cell> {
    exec_public!(amx, "OnPlayerNameChanged"; player_id, old_name => string, new_name => string) 
}
Documentation and examples
Here is documentation and there is an example plugin (Memcached library) and here is a more simple example.

Repository
https://github.com/ZOTTCE/samp-sdk

Ask your questions and more popular will be in wiki on GitHub.


Re: Rust SA:MP SDK - Sia - 14.03.2018

Nice proga SDK plygin


Re: Rust SA:MP SDK - YourShadow - 14.03.2018

Very good.


Re: Rust SA:MP SDK - Kaperstone - 14.03.2018

Awesome!


Re: Rust SA:MP SDK - KayJ - 15.03.2018

Nice


Re: Rust SA:MP SDK - SyS - 15.03.2018

Nice


Re: Rust SA:MP SDK - Zeth - 15.03.2018

Amazing!


Re: Rust SA:MP SDK - KashCherry - 15.03.2018

Nice


Re: Rust SA:MP SDK - NaS - 15.03.2018

Nice, definitely going to try it out.


Re: Rust SA:MP SDK - PT - 15.03.2018

It’s very interesting this plugin

Nice work


Re: Rust SA:MP SDK - Kaperstone - 15.03.2018

Made an example code of usage.
https://github.com/Kaperstone/samp-rust-example


Re: Rust SA:MP SDK - EvaBaka - 15.03.2018

Check out Get Started wiki page.


Re: Rust SA:MP SDK - Kaperstone - 15.03.2018

Quote:
Originally Posted by EvaBaka
Посмотреть сообщение
Check out Get Started wiki page.
You have forgotten to state that nightly toolchain needs to be installed.

or otherwise it will error
Код:
  --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/samp-sdk-0.8.1/src/lib.rs:12:1
   |
12 | #![feature(macro_reexport)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `samp-sdk`.

To learn more, run the command again with --verbose.