modup_api/lib.rs
1// Copyright 2025 Jaroslav Vizner
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::ffi::c_void;
16
17/// Messages that can be sent from the host to the plugin
18#[repr(C)]
19#[derive(Debug, Clone)]
20pub enum FfiMessage {
21 InputChanged,
22 TextChanged(String),
23 Submit,
24}
25
26/// Virtual table every plugin must expose
27#[repr(C)]
28pub struct ModuleVTable {
29 pub new: unsafe extern "C" fn() -> *mut c_void,
30 pub drop: unsafe extern "C" fn(state: *mut c_void),
31 pub update: unsafe extern "C" fn(state: *mut c_void, message: FfiMessage) -> *mut c_void,
32 pub view: unsafe extern "C" fn(state: *mut c_void) -> *mut c_void,
33 pub subscription: unsafe extern "C" fn(state: *mut c_void) -> *mut c_void,
34}
35
36pub type PluginInitFn = unsafe extern "C" fn() -> *const ModuleVTable;