You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Impl Blocks**: Methods are defined separately from type definitions using `impl` blocks
22
21
-**Type Annotations**: Optional but explicit type annotations with `:` for safer scripts
23
22
-**Arrow Syntax**: Function return types specified with `->`
24
-
-**Traits**: Rust-style trait system for defining shared behavior
25
23
-**Memory Safety Focus**: Controlled mutability helps prevent common scripting errors
26
24
27
25
## Syntax Overview
@@ -39,7 +37,8 @@ let opt_var: i32? = 5; // Optional type
39
37
let mut opt_mut: f32? = 2.0; // Optional mutable type
40
38
```
41
39
42
-
**Optional Types**: Types can be marked as optional using the `?` suffix. Optional types can hold a value or be null, providing safer handling of potentially absent values.
40
+
**Optional Types**: Types can be marked as optional using the `?` suffix. Optional types can hold a value or be null,
41
+
providing safer handling of potentially absent values.
43
42
44
43
### Functions
45
44
@@ -142,47 +141,6 @@ let comparison = x > y && z <= w;
142
141
let negation = -value;
143
142
```
144
143
145
-
### Traits
146
-
147
-
Define shared behavior across types with traits:
148
-
149
-
```tea
150
-
trait Drawable {
151
-
fn draw();
152
-
fn area() -> f32;
153
-
}
154
-
155
-
trait Movable {
156
-
fn mut move_to(x: f32, y: f32);
157
-
fn get_position() -> Point;
158
-
}
159
-
```
160
-
161
-
Implement traits for structs:
162
-
163
-
```tea
164
-
impl Drawable for Rectangle {
165
-
fn draw() {
166
-
// Draw rectangle implementation
167
-
}
168
-
169
-
fn area() -> f32 {
170
-
return self.width * self.height;
171
-
}
172
-
}
173
-
174
-
impl Movable for Rectangle {
175
-
fn mut move_to(x: f32, y: f32) {
176
-
self.x = x;
177
-
self.y = y;
178
-
}
179
-
180
-
fn get_position() -> Point {
181
-
return new Point { x: self.x, y: self.y };
182
-
}
183
-
}
184
-
```
185
-
186
144
## Data Types
187
145
188
146
-`i32` - 32-bit signed integer numbers
@@ -238,7 +196,8 @@ Native functions in C must follow this signature:
The function receives a context and a list of arguments, and must return a `tea_value_t`. Arguments are accessed by calling `tea_function_args_pop()` in a loop. Here's an example:
199
+
The function receives a context and a list of arguments, and must return a `tea_value_t`. Arguments are accessed by
200
+
calling `tea_function_args_pop()` in a loop. Here's an example:
242
201
243
202
```c
244
203
// Native function to print values (similar to built-in print)
@@ -348,9 +307,9 @@ Native functions work with the `tea_val_t` type system:
348
307
349
308
1.**Always validate arguments**: Use `tea_fn_args_pop()` to safely access arguments and check for NULL
350
309
2.**Handle errors gracefully**: Return `tea_val_undef()` for error conditions
351
-
3.**Memory management**:
352
-
- Always call `tea_free_var(context, arg)` for each argument you pop
353
-
- Strings returned from native functions should be allocated with `tea_malloc`
310
+
3.**Memory management**:
311
+
- Always call `tea_free_var(context, arg)` for each argument you pop
312
+
- Strings returned from native functions should be allocated with `tea_malloc`
354
313
4.**Performance**: Use native functions for computationally intensive operations
355
314
5.**Argument handling**: Process arguments in the order they were passed by calling `tea_fn_args_pop()` sequentially
0 commit comments