Гайд по использованию на русском языке можно посмотреть здесь и задать вопросы по использованию, но не оставляйте там комментарии об ошибках, т.к. там сложно это обсуждать. Лучше создайте issue в этом репозитории.

Library for simple 1C:Enterprise platform Native API Component development, originates from findings of this medigor/example-native-api-rs

Crate is tested on Linux and Windows. It should work on MacOS as well, but it is not tested.

Structure

Library is divided into two submodules: - native_api_1c_core describes all necessary for implementing 1C:Enterprise Native API - native_api_1c_macro provides a tool for significant simplification of component implementation, taking care of native_api_1c_core::interface::AddInWrapper property implementation

Usage

Attributes #[add_in_prop(...)]

Available property types: i32, f64, bool, String

Functions or procedures #[add_in_func(...)]

Example

```toml

Cargo.toml

[package] name = "my_addin" version = "0.1.0" edition = "2021"

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

[dependencies] utf16lit = "2.0" nativeapi_1c = "0.10.3" ```

```rust // src/lib.rs use std::sync::Arc;

use nativeapi1c::{nativeapi1ccore::ffi::connection::Connection, nativeapi1cmacro::AddIn};

[derive(AddIn)]

pub struct MyAddIn { /// connection with 1C, used for calling events /// Arc is used to allow multiple threads to access the connection #[addincon] connection: Arc>,

/// Property, readable and writable from 1C
#[add_in_prop(name = "MyProp", name_ru = "МоеСвойство", readable, writable)]
pub some_prop: i32,

/// Property, readable from 1C but not writable
#[add_in_prop(name = "ProtectedProp", name_ru = "ЗащищенноеСвойство", readable)]
pub protected_prop: i32,

/// Function, taking one or two arguments and returning a result
/// In 1C it can be called as:
///  ComponentObject.MyFunction(10, 15); // 2nd argument = 15
///  ComponentObject.MyFunction(10);     // 2nd argument = 12 (default value)
/// If function returns an error, but does not panic, then 1C will throw an exception 
#[add_in_func(name = "MyFunction", name_ru = "МояФункция")]
#[arg(Int)]
#[arg(Int, default = 12)]
#[returns(Int, result)]
pub my_function: fn(&Self, i32, i64) -> Result<i32, ()>,

/// Function, taking no arguments and returning nothing 
#[add_in_func(name = "MyProcedure", name_ru = "МояПроцедура")]
pub my_procedure: fn(&mut Self),

/// Private field, not visible from 1C
private_field: i32,

}

impl MyAddIn { pub fn new() -> Self { Self { connection: Arc::new(None), someprop: 0, protectedprop: 50, myfunction: Self::myfunction, myprocedure: Self::myprocedure, private_field: 100, } }

fn my_function(&self, arg: i32, arg_maybe_default: i64) -> Result<i32, ()> {
    Ok(self.protected_prop
        + self.some_prop
        + arg
        + self.private_field
        + arg_maybe_default as i32)
}

fn my_procedure(&mut self) {
    self.protected_prop += 1;
}

} ```