You've already forked native_api_1c
mirror of
https://github.com/Sebekerga/native_api_1c.git
synced 2025-07-15 01:04:16 +02:00
renamed macros and reverted sample addin
This commit is contained in:
16
.github/workflows/test.yml
vendored
16
.github/workflows/test.yml
vendored
@ -8,7 +8,7 @@ env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
build-sample-addin:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@ -16,8 +16,18 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install mingw-w64
|
||||
run: sudo apt-get -y install mingw-w64
|
||||
- name: Install target
|
||||
run: rustup target add x86_64-pc-windows-gnu
|
||||
- name: Build sample AddIn
|
||||
working-directory: ./sample_addin_rs
|
||||
run: cargo build
|
||||
|
||||
test-macros:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install mingw-w64
|
||||
run: sudo apt-get -y install mingw-w64
|
||||
- name: Build macros
|
||||
working-directory: ./
|
||||
run: cargo test -p native_api_1c_macro
|
@ -5,13 +5,6 @@ fn trybuild_props() {
|
||||
t.pass("tests/trybuild/to_build/props.rs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trybuild_example() {
|
||||
let t = trybuild::TestCases::new();
|
||||
|
||||
t.pass("tests/trybuild/to_build/readme_example.rs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trybuild_functions() {
|
||||
let t = trybuild::TestCases::new();
|
||||
|
@ -1,77 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use native_api_1c::{
|
||||
native_api_1c_core::ffi::connection::Connection,
|
||||
native_api_1c_macro::{extern_functions, AddIn},
|
||||
};
|
||||
|
||||
#[derive(AddIn)]
|
||||
pub struct SampleAddIn {
|
||||
/// connection with 1C, used for calling events
|
||||
/// Arc is used to allow multiple threads to access the connection
|
||||
#[add_in_con]
|
||||
connection: Arc<Option<&'static Connection>>,
|
||||
|
||||
/// Property, readable and writable from 1C
|
||||
#[add_in_prop(ty = Int, name = "MyProp", name_ru = "МоеСвойство", readable, writable)]
|
||||
pub some_prop: i32,
|
||||
|
||||
/// Property, readable from 1C but not writable
|
||||
#[add_in_prop(ty = Int, 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:
|
||||
/// ```bsl
|
||||
/// 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(ty = Int)]
|
||||
#[arg(ty = Int, default = 12)]
|
||||
#[returns(ty = 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 Default for SampleAddIn {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
connection: Arc::new(None),
|
||||
some_prop: 0,
|
||||
protected_prop: 50,
|
||||
my_function: Self::my_function_inner,
|
||||
my_procedure: Self::my_procedure_inner,
|
||||
private_field: 100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SampleAddIn {
|
||||
fn my_function_inner(&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_inner(&mut self) {
|
||||
self.protected_prop += 10;
|
||||
}
|
||||
}
|
||||
|
||||
extern_functions! {
|
||||
SampleAddIn::default(),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _add_in = SampleAddIn::default();
|
||||
}
|
@ -1,28 +1,73 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use native_api_1c::native_api_1c_core::ffi::connection::Connection;
|
||||
use native_api_1c::native_api_1c_macro::AddIn;
|
||||
use native_api_1c::{
|
||||
native_api_1c_core::ffi::connection::Connection,
|
||||
native_api_1c_macro::{extern_functions, AddIn},
|
||||
};
|
||||
|
||||
#[derive(AddIn)]
|
||||
pub struct MyAddIn {
|
||||
pub struct SampleAddIn {
|
||||
/// connection with 1C, used for calling events
|
||||
/// Arc is used to allow multiple threads to access the connection
|
||||
#[add_in_con]
|
||||
connection: Arc<Option<&'static Connection>>,
|
||||
|
||||
/// Property, readable and writable from 1C
|
||||
#[add_in_prop(ty = Int, name = "MyProp", name_ru = "МоеСвойство", readable, writable)]
|
||||
pub some_prop: i32,
|
||||
|
||||
/// Property, readable from 1C but not writable
|
||||
#[add_in_prop(ty = Int, 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:
|
||||
/// ```bsl
|
||||
/// CompObj.MyFunction(10, 15); // 2nd arg = 15
|
||||
/// CompObj.MyFunction(10); // 2nd arg = 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(ty = Str, default = "")]
|
||||
#[returns(ty = Str)]
|
||||
pub my_function: fn(&Self, String) -> String,
|
||||
#[arg(ty = Int)]
|
||||
#[arg(ty = Int, default = 12)] // default value for the second argument
|
||||
#[returns(ty = 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 {
|
||||
impl Default for SampleAddIn {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
connection: Arc::new(None),
|
||||
some_prop: 0,
|
||||
protected_prop: 50,
|
||||
my_function: Self::my_function_inner,
|
||||
my_procedure: Self::my_procedure_inner,
|
||||
private_field: 100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn my_function_inner(&self, arg: String) -> String {
|
||||
arg
|
||||
impl SampleAddIn {
|
||||
fn my_function_inner(&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_inner(&mut self) {
|
||||
self.protected_prop += 10;
|
||||
}
|
||||
}
|
||||
|
||||
extern_functions! {
|
||||
SampleAddIn::default(),
|
||||
}
|
||||
|
Reference in New Issue
Block a user