1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
//! # Plux - Extensible Plugin System for Rust
//!
//! Plux is a comprehensive plugin system for Rust applications, offering a robust and flexible
//! architecture for extending application functionality through plugins. It enables seamless
//! integration of third-party code while maintaining security and stability.
//!
//! ## Key Features
//!
//! - **Language Agnostic**: Write plugins in any programming language
//! - **Hot Reloading**: Update plugins without restarting the host application
//! - **Dynamic Loading**: Load and unload plugins at runtime
//! - **Type Safety**: Rust's type system ensures safe plugin interactions
//! - **Cross-Platform**: Works on all major platforms (Windows, macOS, Linux)
//! - **Performance Optimized**: Efficient loading and caching of plugins
//! - **Isolated Execution**: Secure sandboxing for plugin execution
//!
//! ## Core Components
//!
//! - **Loader**: Central component for managing plugin lifecycle and execution
//! - **Manager**: Adapters providing standardized interfaces for plugin integration
//! - **Plugin**: Self-contained modules that extend application functionality
//!
//! ## Quick Start
//!
//! ```rust,no_run,ignore
//! use plux_rs::prelude::*;
//! use plux_lua_manager::LuaManager;
//!
//! #[function]
//! fn add(_: (), a: &i32, b: &i32) -> i32 {
//! a + b
//! }
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut loader = SimpleLoader::new();
//!
//! loader.context(move |mut ctx| {
//! ctx.register_manager(LuaManager::new())?;
//! ctx.register_function(add());
//!
//! // Load and manage plugins here
//! Ok::<(), Box<dyn std::error::Error>>(())
//! })?;
//!
//! Ok(())
//! }
//! ```
// #![doc(html_logo_url = "https://example.com/logo.png")]
// #![doc(html_favicon_url = "https://example.com/favicon.ico")]
/// Context types used during plugin loading and registration.
///
/// This module provides the context types that are passed to plugin managers
/// during various lifecycle events such as registration and loading.
/// Function and request definitions for the plugin system.
///
/// This module defines the core function and request types that enable
/// communication between plugins and the host application.
/// Utility types and functions for the plugin system.
///
/// This module contains various utility types, error definitions, and helper
/// functions used throughout the plugin system.
/// Variable types used for data exchange between plugins and host.
///
/// This module defines the Variable and VariableType enums that represent
/// the data types that can be passed between plugins and the host application.
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
use ;
use Arc;
/// Registry of functions that can be called by plugins.
/// This type alias represents a collection of functions exposed by the host application
/// that plugins can invoke during execution.
pub type Registry<O> = ;
/// Collection of function requests from plugins.
/// This type alias represents a collection of requests that plugins can make to the host
/// application, typically for accessing host-provided functionality.
pub type Requests = ;
/// A convenience type alias for a Loader with commonly used default type parameters.
///
/// This type alias simplifies the creation of a `Loader` with the following configuration:
/// - `'static` lifetime for the loader itself
/// - `FunctionOutput` as the output type, which is the standard return type for plugin functions
/// - `StdInfo` as the info type, which provides standard plugin information
///
/// # Example
///
/// ```rust
/// use plux_rs::SimpleLoader;
///
/// // Create a new loader with default configuration
/// let loader = SimpleLoader::new();
/// ```
pub type SimpleLoader = ;
/// Macro for convenient function calling with automatic argument conversion.
///
/// This macro simplifies calling functions by automatically converting arguments
/// to Variables and handling the function call syntax.
///
/// # Examples
///
/// ```rust
/// use plux_rs::{function_call, function::{Function, DynamicFunction, Arg, FunctionOutput}};
/// use plux_rs::variable::VariableType;
///
/// let add = DynamicFunction::new(
/// "add",
/// vec![
/// Arg::new("a", VariableType::I32),
/// Arg::new("b", VariableType::I32),
/// ],
/// Some(Arg::new("result", VariableType::I32)),
/// |args| -> FunctionOutput {
/// let a = args[0].parse_ref::<i32>();
/// let b = args[1].parse_ref::<i32>();
/// Ok(Some((a + b).into()))
/// }
/// );
///
/// // Call with arguments
/// let result = function_call!(add, 5, 3);
/// assert_eq!(result.unwrap(), Some(8.into()));
///
/// // Call without arguments
/// let no_args_func = DynamicFunction::new(
/// "hello",
/// vec![],
/// Some(Arg::new("message", VariableType::String)),
/// |_| -> FunctionOutput { Ok(Some("Hello!".into())) }
/// );
/// let message = function_call!(no_args_func);
/// ```
/// Re-exports for procedural macros when the `derive` feature is enabled.
///
/// # Macros
///
/// ## `#[function]`
///
/// A procedural macro that transforms a Rust function into a plugin-compatible function.
/// This macro enables the function to be called from plugins and handles serialization
/// of arguments and return values.
///
/// ### Usage
///
/// ```rust,no_run
/// use plux_rs::prelude::*;
///
/// // Basic usage with primitive types
/// #[plux_rs::function]
/// fn add(_: (), a: &i32, b: &i32) -> i32 {
/// a + b
/// }
///
/// // With references for better performance
/// #[plux_rs::function]
/// fn concat(_: (), a: &String, b: Vec<&String>) -> String {
/// let v = b.into_iter().map(|s| s.clone()).collect::<Vec<String>>();
/// format!("{} {}", a, v.join(" "))
/// }
///
/// // With context parameter (first parameter is always the context)
/// #[plux_rs::function]
/// fn greet(message: &String, name: &Variable) -> String {
/// format!("{} {}", message, name)
/// }
///
/// let mut loader = Loader::<'_, FunctionOutput, StdInfo>::new();
/// loader
/// .context(move |mut ctx| {
/// ctx.register_function(add());
/// ctx.register_function(concat());
/// ctx.register_function(greet("Hello world,".to_string()));
///
/// Ok::<(), Box<dyn std::error::Error>>(())
/// })
/// .unwrap();
///
/// let registry = loader.get_registry();
///
/// let add_function = registry.get(0).unwrap();
/// let concat_function = registry.get(1).unwrap();
/// let greet_function = registry.get(2).unwrap();
///
/// let result = add_function.call(&[1.into(), 2.into()]).unwrap().unwrap();
/// assert_eq!(result, 3.into());
///
/// let result = concat_function
/// .call(&["Hi".into(), vec!["guest", "!"].into()])
/// .unwrap()
/// .unwrap();
/// assert_eq!(result, "Hi guest !".into());
///
/// let result = greet_function.call(&["guest".into()]).unwrap().unwrap();
/// assert_eq!(result, "Hello world, guest".into());
/// ```
///
/// ### Features
///
/// - **Type Safety**: Compile-time type checking of function signatures
/// - **Zero-Copy**: Always uses references to avoid unnecessary cloning
/// - **Context Support**: First parameter can be a context object
///
/// ### Notes
///
/// - The first parameter can be used for context (use `_` if not needed)
/// - Supported parameter types: primitive types, `&T` and `Vec<&T>`
/// - The function will be available to plugins under its Rust name by default
pub use function;
/// Re-export of common types for plugin implementation.
/// This module provides convenient access to the most commonly used types when
/// implementing plugins.