array len with kw args

This commit is contained in:
arnav
2025-01-09 07:20:48 -05:00
parent 34032b6cb7
commit 8b9580b178
5 changed files with 521 additions and 4 deletions

View File

@ -17,7 +17,7 @@ len(array: [KclValue]) -> KclValue
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | | Yes | | `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | The array to get the length of. | Yes |
### Returns ### Returns

View File

@ -90163,7 +90163,7 @@
"summary": "Get the length of an array.", "summary": "Get the length of an array.",
"description": "Returns the number of elements in an array.", "description": "Returns the number of elements in an array.",
"tags": [], "tags": [],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "array", "name": "array",
@ -90703,6 +90703,51 @@
} }
} }
}, },
{
"description": "A helix.",
"type": "object",
"required": [
"__meta",
"angleStart",
"ccw",
"revolutions",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Helix"
]
},
"value": {
"description": "The id of the helix.",
"type": "string",
"format": "uuid"
},
"revolutions": {
"description": "Number of revolutions.",
"type": "number",
"format": "double"
},
"angleStart": {
"description": "Start angle (in degrees).",
"type": "number",
"format": "double"
},
"ccw": {
"description": "Is the helix rotation counter clockwise?",
"type": "boolean"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{ {
"description": "Data for an imported geometry.", "description": "Data for an imported geometry.",
"type": "object", "type": "object",
@ -90764,6 +90809,31 @@
} }
} }
}, },
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Module"
]
},
"value": {
"$ref": "#/components/schemas/ModuleId"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{ {
"type": "object", "type": "object",
"required": [ "required": [
@ -92145,6 +92215,12 @@
} }
} }
}, },
"ModuleId": {
"description": "Identifier of a source file. Uses a u32 to keep the size small.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"KclNone": { "KclNone": {
"description": "KCL value for an optional parameter which was not given an argument. (remember, parameters are in the function declaration, arguments are in the function call/application).", "description": "KCL value for an optional parameter which was not given an argument. (remember, parameters are in the function declaration, arguments are in the function call/application).",
"type": "object", "type": "object",
@ -92165,7 +92241,8 @@
} }
}, },
"required": true, "required": true,
"labelRequired": true "description": "The array to get the length of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -92700,6 +92777,51 @@
} }
} }
}, },
{
"description": "A helix.",
"type": "object",
"required": [
"__meta",
"angleStart",
"ccw",
"revolutions",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Helix"
]
},
"value": {
"description": "The id of the helix.",
"type": "string",
"format": "uuid"
},
"revolutions": {
"description": "Number of revolutions.",
"type": "number",
"format": "double"
},
"angleStart": {
"description": "Start angle (in degrees).",
"type": "number",
"format": "double"
},
"ccw": {
"description": "Is the helix rotation counter clockwise?",
"type": "boolean"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{ {
"description": "Data for an imported geometry.", "description": "Data for an imported geometry.",
"type": "object", "type": "object",
@ -92761,6 +92883,31 @@
} }
} }
}, },
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Module"
]
},
"value": {
"$ref": "#/components/schemas/ModuleId"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{ {
"type": "object", "type": "object",
"required": [ "required": [
@ -93342,6 +93489,51 @@
} }
} }
}, },
{
"description": "A helix.",
"type": "object",
"required": [
"__meta",
"angleStart",
"ccw",
"revolutions",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Helix"
]
},
"value": {
"description": "The id of the helix.",
"type": "string",
"format": "uuid"
},
"revolutions": {
"description": "Number of revolutions.",
"type": "number",
"format": "double"
},
"angleStart": {
"description": "Start angle (in degrees).",
"type": "number",
"format": "double"
},
"ccw": {
"description": "Is the helix rotation counter clockwise?",
"type": "boolean"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{ {
"description": "Data for an imported geometry.", "description": "Data for an imported geometry.",
"type": "object", "type": "object",
@ -93403,6 +93595,31 @@
} }
} }
}, },
{
"type": "object",
"required": [
"__meta",
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Module"
]
},
"value": {
"$ref": "#/components/schemas/ModuleId"
},
"__meta": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Metadata"
}
}
}
},
{ {
"type": "object", "type": "object",
"required": [ "required": [
@ -94757,6 +94974,12 @@
} }
} }
}, },
"ModuleId": {
"description": "Identifier of a source file. Uses a u32 to keep the size small.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"KclNone": { "KclNone": {
"description": "KCL value for an optional parameter which was not given an argument. (remember, parameters are in the function declaration, arguments are in the function call/application).", "description": "KCL value for an optional parameter which was not given an argument. (remember, parameters are in the function declaration, arguments are in the function call/application).",
"type": "object", "type": "object",

View File

@ -320,6 +320,11 @@ pub async fn pop(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
/// ``` /// ```
#[stdlib { #[stdlib {
name = "len", name = "len",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to get the length of.",
}
}] }]
async fn inner_len(array: Vec<KclValue>, args: &Args) -> Result<KclValue, KclError> { async fn inner_len(array: Vec<KclValue>, args: &Args) -> Result<KclValue, KclError> {
Ok(KclValue::Number { Ok(KclValue::Number {
@ -329,7 +334,7 @@ async fn inner_len(array: Vec<KclValue>, args: &Args) -> Result<KclValue, KclErr
} }
pub async fn len(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn len(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let val: KclValue = FromArgs::from_args(&args, 0)?; let val = args.get_unlabeled_kw_arg("array")?;
let meta = vec![args.source_range]; let meta = vec![args.source_range];
let KclValue::Array { value: array, meta: _ } = val else { let KclValue::Array { value: array, meta: _ } = val else {
let actual_type = val.human_friendly_type(); let actual_type = val.human_friendly_type();

View File

@ -0,0 +1,284 @@
---
source: kcl/src/simulation_tests.rs
description: Artifact commands array_length.kcl
---
[
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "plane_set_color",
"plane_id": "[uuid]",
"color": {
"r": 0.7,
"g": 0.28,
"b": 0.28,
"a": 0.4
}
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "plane_set_color",
"plane_id": "[uuid]",
"color": {
"r": 0.28,
"g": 0.7,
"b": 0.28,
"a": 0.4
}
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "plane_set_color",
"plane_id": "[uuid]",
"color": {
"r": 0.28,
"g": 0.28,
"b": 0.7,
"a": 0.4
}
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": -1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 0.0,
"y": -1.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": -1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "edge_lines_visible",
"hidden": false
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "set_scene_units",
"unit": "mm"
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
}
]

View File

@ -0,0 +1,5 @@
---
source: kcl/src/simulation_tests.rs
description: Operations executed array_length.kcl
---
[]