Skip to main content

factorio_ir/ast/
function.rs

1use crate::ast::{block::Block, r#type::Type};
2use crate::meta::debug::FunctionDebug;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct Parameter {
6    pub name: String,
7    pub r#type: Type,
8    pub source_type: Option<String>,
9}
10
11/// Metadata from `#[factorio_rs::export]` / `#[factorio_rs::export(interface = "...")]`.
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct ExportMeta {
14    /// Override for the Factorio remote interface name (control-stage exports).
15    /// When `None`, the consuming mod's package name is used at emit time.
16    pub interface: Option<String>,
17}
18
19#[derive(Debug, Clone, PartialEq)]
20pub struct Function {
21    pub name: String,
22    pub params: Vec<Parameter>,
23    pub body: Block,
24    pub doc: Option<String>,
25    pub debug: Option<FunctionDebug>,
26    /// Factorio event name when this function is registered with `#[factorio_rs::event(...)]`.
27    pub event: Option<String>,
28    /// Optional event filter table passed to `script.on_event`.
29    pub event_filter: Option<crate::expression::Expression>,
30    /// Present when marked with `#[factorio_rs::export]`.
31    pub export: Option<ExportMeta>,
32    /// `#[factorio_rs::inline]`: shared-stage hot path; dependents bind via `require`
33    /// (never `remote.call`). Implies [`Self::export`].
34    pub inline: bool,
35}