sciter/capi/scvalue.rs
1//! Sciter value, native C interface.
2
3#![allow(non_snake_case, non_camel_case_types)]
4#![allow(dead_code)]
5
6use capi::sctypes::*;
7
8/// A JSON value.
9///
10/// An opaque union that can hold different types of values: numbers, strings, arrays, objects, etc.
11#[repr(C)]
12#[derive(Default, Debug, Clone)]
13pub struct VALUE
14{
15 /// Value type.
16 pub t: VALUE_TYPE,
17
18 /// Value unit type.
19 pub u: UINT,
20
21 /// Value data.
22 pub d: UINT64,
23}
24
25impl VALUE {
26 /// `undefined`
27 pub(crate) const fn new() -> Self {
28 Self {
29 t: VALUE_TYPE::T_UNDEFINED,
30 u: 0,
31 d: 0,
32 }
33 }
34}
35
36#[repr(C)]
37#[derive(Debug, PartialOrd, PartialEq)]
38pub enum VALUE_RESULT
39{
40 OK_TRUE = -1,
41 OK = 0,
42 BAD_PARAMETER = 1,
43 INCOMPATIBLE_TYPE = 2,
44}
45
46impl std::error::Error for VALUE_RESULT {}
47
48impl std::fmt::Display for VALUE_RESULT {
49 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
50 write!(f, "{:?}", self)
51 }
52}
53
54
55#[repr(C)]
56#[derive(Debug, PartialOrd, PartialEq)]
57pub enum VALUE_STRING_CVT_TYPE {
58 SIMPLE = 0,
59 JSON_LITERAL = 1,
60 JSON_MAP = 2,
61 XJSON_LITERAL = 3,
62}
63
64
65/// Type identifier of the value.
66#[repr(C)]
67#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
68pub enum VALUE_TYPE {
69 /// Just undefined, the data is zero, the unit can be [`UT_NOTHING`](VALUE_UNIT_UNDEFINED::UT_NOTHING).
70 T_UNDEFINED = 0,
71 /// Explicit `null` type, the rest fields are zero.
72 T_NULL = 1,
73 /// Data is `1` or `0`; units can be used but unknown.
74 T_BOOL,
75 /// Data is an integer; units can be used but unknown.
76 T_INT,
77 /// Data is a double float; units can be used but unknown.
78 T_FLOAT,
79 /// Data is a Sciter internal string, unit is [`VALUE_UNIT_TYPE_STRING`].
80 T_STRING,
81 /// Data is `FILETIME` (64-bit value in 100ns since the unix epoch).
82 /// No unit is stored but `is_utc` boolean is used during creation.
83 T_DATE,
84 /// Data is a 64-bit number, no units.
85 T_CURRENCY,
86 /// Data is a float (but can be constructed from an int), unit is [`VALUE_UNIT_TYPE_LENGTH`].
87 T_LENGTH,
88 /// Sciter internal array, unit is [`VALUE_UNIT_TYPE_ARRAY`].
89 T_ARRAY,
90 /// Sciter internal array of key-value pairs.
91 T_MAP,
92 /// Sciter internal function, holds its name and params.
93 T_FUNCTION,
94 /// Sciter internal array of bytes.
95 T_BYTES,
96 /// Sciter internal object, unit is `[VALUE_UNIT_TYPE_OBJECT`].
97 T_OBJECT,
98 /// Sciter internal object.
99 T_DOM_OBJECT,
100 /// Sciter-managed resource object.
101 T_RESOURCE,
102 /// `N..M` range as a 32-bit integer pair, units are zero.
103 T_RANGE,
104 /// Time duration as a float, in seconds or milliseconds (depends on the unit).
105 T_DURATION,
106 /// Angle radians as a float, unit is [`VALUE_UNIT_TYPE_ANGLE`].
107 T_ANGLE,
108 /// Color in ARGB format as a 32-bit number.
109 T_COLOR,
110 /// Sciter internal array of value-name pairs.
111 T_ENUM,
112 /// Sciter asset.
113 T_ASSET,
114
115 T_UNKNOWN,
116}
117
118impl Default for VALUE_TYPE {
119 fn default() -> Self {
120 Self::T_UNDEFINED
121 }
122}
123
124/// `undefined` sub-state.
125#[repr(C)]
126#[derive(Debug, PartialOrd, PartialEq)]
127pub enum VALUE_UNIT_UNDEFINED
128{
129 /// 'nothing' a.k.a. 'void' value in script.
130 UT_NOTHING = 1,
131}
132
133/// String sub-types.
134#[repr(C)]
135#[derive(Debug, PartialOrd, PartialEq)]
136pub enum VALUE_UNIT_TYPE_STRING
137{
138 STRING = 0, // string
139 ERROR = 1, // is an error string
140 SECURE = 2, // secure string ("wiped" on destroy)
141 URL = 3, // url(...)
142 SELECTOR = 4, // selector(...)
143 FILE = 0xfffe, // file name
144 SYMBOL = 0xffff, // symbol in tiscript sense
145}
146
147/// Length sub-types.
148#[repr(C)]
149#[derive(Debug, PartialOrd, PartialEq)]
150pub enum VALUE_UNIT_TYPE_LENGTH
151{
152 EM = 1, //height of the element's font.
153 EX = 2, //height of letter 'x'
154 PR = 3, //%
155 SP = 4, //%% "springs", a.k.a. flex units
156 PX = 7, //pixels
157 IN = 8, //inches (1 inch = 2.54 centimeters).
158 CM = 9, //centimeters.
159 MM = 10, //millimeters.
160 PT = 11, //points (1 point = 1/72 inches).
161 PC = 12, //picas (1 pica = 12 points).
162 DIP = 13,
163 URL = 16, // url in string
164}
165
166/// Array sub-types.
167#[repr(C)]
168#[derive(Debug, PartialOrd, PartialEq)]
169pub enum VALUE_UNIT_TYPE_ARRAY
170{
171 /// White space separated list.
172 WT_LIST = 1,
173 /// Comma separated list.
174 CS_LIST,
175 /// Slash separated pair.
176 PAIR,
177}
178
179// Sciter or TIScript specific
180#[repr(C)]
181#[derive(Debug, PartialOrd, PartialEq)]
182pub enum VALUE_UNIT_TYPE_OBJECT
183{
184 ARRAY = 0, // type T_OBJECT of type Array
185 OBJECT = 1, // type T_OBJECT of type Object
186 CLASS = 2, // type T_OBJECT of type Class (class or namespace)
187 NATIVE = 3, // type T_OBJECT of native Type with data slot (LPVOID)
188 FUNCTION = 4, // type T_OBJECT of type Function
189 ERROR = 5, // type T_OBJECT of type Error
190}
191
192pub type NATIVE_FUNCTOR_INVOKE = extern "C" fn (tag: LPVOID, argc: UINT, argv: *const VALUE, retval: * mut VALUE);
193pub type NATIVE_FUNCTOR_RELEASE = extern "C" fn (tag: LPVOID);