rs_web/lua/
types.rs

1//! Lua API type definitions for EmmyLua annotations
2
3/// A Lua function definition
4#[derive(Debug, Clone)]
5pub struct LuaFunction {
6    pub name: &'static str,
7    pub module: Option<&'static str>,
8    pub description: &'static str,
9    pub params: &'static [LuaParam],
10    pub returns: &'static str,
11    /// For generic return types like AsyncIOTask<T>, specifies what T is
12    pub generic_return: Option<&'static str>,
13}
14
15/// A Lua function parameter
16#[derive(Debug, Clone)]
17pub struct LuaParam {
18    pub name: &'static str,
19    pub typ: &'static str,
20    pub description: &'static str,
21    pub optional: bool,
22}
23
24/// A Lua class/table type definition
25#[derive(Debug, Clone)]
26pub struct LuaClass {
27    pub name: &'static str,
28    pub description: &'static str,
29    pub fields: &'static [LuaField],
30    /// Whether this class is generic (e.g., AsyncIOTask<T>)
31    pub is_generic: bool,
32}
33
34/// A field in a Lua class
35#[derive(Debug, Clone)]
36pub struct LuaField {
37    pub name: &'static str,
38    pub typ: &'static str,
39    pub description: &'static str,
40}
41
42// ============================================================================
43// CLASS DEFINITIONS
44// ============================================================================
45
46pub static LUA_CLASSES: &[LuaClass] = &[
47    LuaClass {
48        name: "AsyncTask",
49        description: "Async task handle for fetch operations",
50        is_generic: true,
51        fields: &[LuaField {
52            name: "is_completed",
53            typ: "fun(): boolean",
54            description: "Check if task is completed",
55        }],
56    },
57    LuaClass {
58        name: "AsyncIOTask",
59        description: "Async task handle for I/O operations",
60        is_generic: true,
61        fields: &[LuaField {
62            name: "is_completed",
63            typ: "fun(): boolean",
64            description: "Check if task is completed",
65        }],
66    },
67    LuaClass {
68        name: "AsyncLuaTask",
69        description: "Async task handle for wrapped Lua functions",
70        is_generic: true,
71        fields: &[LuaField {
72            name: "is_completed",
73            typ: "fun(): boolean",
74            description: "Check if task is completed",
75        }],
76    },
77    LuaClass {
78        name: "FetchResponse",
79        description: "HTTP response from fetch operations",
80        is_generic: false,
81        fields: &[
82            LuaField {
83                name: "status",
84                typ: "number",
85                description: "HTTP status code",
86            },
87            LuaField {
88                name: "ok",
89                typ: "boolean",
90                description: "True if status is 2xx",
91            },
92            LuaField {
93                name: "body",
94                typ: "string",
95                description: "Response body",
96            },
97            LuaField {
98                name: "headers",
99                typ: "table<string, string>",
100                description: "Response headers",
101            },
102            LuaField {
103                name: "json",
104                typ: "fun(): any",
105                description: "Parse body as JSON",
106            },
107        ],
108    },
109    LuaClass {
110        name: "FileMetadata",
111        description: "File metadata from async.metadata",
112        is_generic: false,
113        fields: &[
114            LuaField {
115                name: "is_file",
116                typ: "boolean",
117                description: "True if path is a file",
118            },
119            LuaField {
120                name: "is_dir",
121                typ: "boolean",
122                description: "True if path is a directory",
123            },
124            LuaField {
125                name: "len",
126                typ: "number",
127                description: "File size in bytes",
128            },
129            LuaField {
130                name: "readonly",
131                typ: "boolean",
132                description: "True if file is read-only",
133            },
134            LuaField {
135                name: "modified",
136                typ: "number?",
137                description: "Unix timestamp of last modification",
138            },
139        ],
140    },
141    LuaClass {
142        name: "DirEntry",
143        description: "Directory entry from async.read_dir",
144        is_generic: false,
145        fields: &[
146            LuaField {
147                name: "path",
148                typ: "string",
149                description: "Full path to entry",
150            },
151            LuaField {
152                name: "name",
153                typ: "string",
154                description: "Entry name",
155            },
156            LuaField {
157                name: "is_file",
158                typ: "boolean",
159                description: "True if entry is a file",
160            },
161            LuaField {
162                name: "is_dir",
163                typ: "boolean",
164                description: "True if entry is a directory",
165            },
166            LuaField {
167                name: "is_symlink",
168                typ: "boolean",
169                description: "True if entry is a symlink",
170            },
171        ],
172    },
173    LuaClass {
174        name: "FileInfo",
175        description: "File metadata",
176        is_generic: false,
177        fields: &[
178            LuaField {
179                name: "path",
180                typ: "string",
181                description: "Absolute path",
182            },
183            LuaField {
184                name: "name",
185                typ: "string",
186                description: "Full filename with extension",
187            },
188            LuaField {
189                name: "stem",
190                typ: "string",
191                description: "Filename without extension",
192            },
193            LuaField {
194                name: "ext",
195                typ: "string",
196                description: "File extension",
197            },
198            LuaField {
199                name: "is_dir",
200                typ: "boolean",
201                description: "Whether this is a directory",
202            },
203            LuaField {
204                name: "modified",
205                typ: "number|nil",
206                description: "Unix timestamp of last modification",
207            },
208        ],
209    },
210    LuaClass {
211        name: "FrontmatterResult",
212        description: "Result of reading frontmatter from a file. Frontmatter fields are merged to top level.",
213        is_generic: false,
214        fields: &[
215            LuaField {
216                name: "raw",
217                typ: "string",
218                description: "Original file content",
219            },
220            LuaField {
221                name: "content",
222                typ: "string",
223                description: "Content after frontmatter",
224            },
225            LuaField {
226                name: "[string]",
227                typ: "any",
228                description: "Additional frontmatter fields",
229            },
230        ],
231    },
232    LuaClass {
233        name: "GitInfo",
234        description: "Git repository/file information",
235        is_generic: false,
236        fields: &[
237            LuaField {
238                name: "hash",
239                typ: "string",
240                description: "Full commit hash",
241            },
242            LuaField {
243                name: "short_hash",
244                typ: "string",
245                description: "Short commit hash (7 chars)",
246            },
247            LuaField {
248                name: "date",
249                typ: "string",
250                description: "Commit date (YYYY-MM-DD)",
251            },
252            LuaField {
253                name: "author",
254                typ: "string?",
255                description: "Commit author (for file commits)",
256            },
257            LuaField {
258                name: "branch",
259                typ: "string?",
260                description: "Current branch (for repo info)",
261            },
262            LuaField {
263                name: "dirty",
264                typ: "boolean?",
265                description: "Whether repo has uncommitted changes",
266            },
267        ],
268    },
269    LuaClass {
270        name: "ImageDimensions",
271        description: "Image dimensions",
272        is_generic: false,
273        fields: &[
274            LuaField {
275                name: "width",
276                typ: "number",
277                description: "Width in pixels",
278            },
279            LuaField {
280                name: "height",
281                typ: "number",
282                description: "Height in pixels",
283            },
284        ],
285    },
286];
287
288// ============================================================================
289// FUNCTION DEFINITIONS
290// ============================================================================
291
292pub static LUA_FUNCTIONS: &[LuaFunction] = &[
293    // ========================================================================
294    // rs.ops - Collection Operations
295    // ========================================================================
296    LuaFunction {
297        name: "map",
298        module: Some("ops"),
299        description: "Transform each item using function",
300        params: &[
301            LuaParam {
302                name: "items",
303                typ: "T[]",
304                description: "Items to transform",
305                optional: false,
306            },
307            LuaParam {
308                name: "fn",
309                typ: "fun(item: T): U",
310                description: "Transform function",
311                optional: false,
312            },
313        ],
314        returns: "U[]",
315        generic_return: None,
316    },
317    LuaFunction {
318        name: "filter",
319        module: Some("ops"),
320        description: "Filter items using predicate function",
321        params: &[
322            LuaParam {
323                name: "items",
324                typ: "T[]",
325                description: "Items to filter",
326                optional: false,
327            },
328            LuaParam {
329                name: "fn",
330                typ: "fun(item: T): boolean",
331                description: "Predicate function",
332                optional: false,
333            },
334        ],
335        returns: "T[]",
336        generic_return: None,
337    },
338    LuaFunction {
339        name: "sort",
340        module: Some("ops"),
341        description: "Sort items using comparator function",
342        params: &[
343            LuaParam {
344                name: "items",
345                typ: "T[]",
346                description: "Items to sort",
347                optional: false,
348            },
349            LuaParam {
350                name: "fn",
351                typ: "fun(a: T, b: T): boolean",
352                description: "Comparator (true if a < b)",
353                optional: false,
354            },
355        ],
356        returns: "T[]",
357        generic_return: None,
358    },
359    LuaFunction {
360        name: "find",
361        module: Some("ops"),
362        description: "Find first item matching predicate",
363        params: &[
364            LuaParam {
365                name: "items",
366                typ: "T[]",
367                description: "Items to search",
368                optional: false,
369            },
370            LuaParam {
371                name: "fn",
372                typ: "fun(item: T): boolean",
373                description: "Predicate function",
374                optional: false,
375            },
376        ],
377        returns: "T|nil",
378        generic_return: None,
379    },
380    LuaFunction {
381        name: "group_by",
382        module: Some("ops"),
383        description: "Group items by key returned by function",
384        params: &[
385            LuaParam {
386                name: "items",
387                typ: "T[]",
388                description: "Items to group",
389                optional: false,
390            },
391            LuaParam {
392                name: "fn",
393                typ: "fun(item: T): string",
394                description: "Key function",
395                optional: false,
396            },
397        ],
398        returns: "table<string, T[]>",
399        generic_return: None,
400    },
401    LuaFunction {
402        name: "unique",
403        module: Some("ops"),
404        description: "Remove duplicate items",
405        params: &[LuaParam {
406            name: "items",
407            typ: "T[]",
408            description: "Items to deduplicate",
409            optional: false,
410        }],
411        returns: "T[]",
412        generic_return: None,
413    },
414    LuaFunction {
415        name: "reverse",
416        module: Some("ops"),
417        description: "Reverse array order",
418        params: &[LuaParam {
419            name: "items",
420            typ: "T[]",
421            description: "Items to reverse",
422            optional: false,
423        }],
424        returns: "T[]",
425        generic_return: None,
426    },
427    LuaFunction {
428        name: "take",
429        module: Some("ops"),
430        description: "Take first n items",
431        params: &[
432            LuaParam {
433                name: "items",
434                typ: "T[]",
435                description: "Items",
436                optional: false,
437            },
438            LuaParam {
439                name: "n",
440                typ: "number",
441                description: "Number of items to take",
442                optional: false,
443            },
444        ],
445        returns: "T[]",
446        generic_return: None,
447    },
448    LuaFunction {
449        name: "skip",
450        module: Some("ops"),
451        description: "Skip first n items",
452        params: &[
453            LuaParam {
454                name: "items",
455                typ: "T[]",
456                description: "Items",
457                optional: false,
458            },
459            LuaParam {
460                name: "n",
461                typ: "number",
462                description: "Number of items to skip",
463                optional: false,
464            },
465        ],
466        returns: "T[]",
467        generic_return: None,
468    },
469    LuaFunction {
470        name: "keys",
471        module: Some("ops"),
472        description: "Get all keys from a table",
473        params: &[LuaParam {
474            name: "table",
475            typ: "table",
476            description: "Table to get keys from",
477            optional: false,
478        }],
479        returns: "any[]",
480        generic_return: None,
481    },
482    LuaFunction {
483        name: "values",
484        module: Some("ops"),
485        description: "Get all values from a table",
486        params: &[LuaParam {
487            name: "table",
488            typ: "table",
489            description: "Table to get values from",
490            optional: false,
491        }],
492        returns: "any[]",
493        generic_return: None,
494    },
495    LuaFunction {
496        name: "reduce",
497        module: Some("ops"),
498        description: "Reduce items to single value",
499        params: &[
500            LuaParam {
501                name: "items",
502                typ: "T[]",
503                description: "Items to reduce",
504                optional: false,
505            },
506            LuaParam {
507                name: "initial",
508                typ: "U",
509                description: "Initial accumulator value",
510                optional: false,
511            },
512            LuaParam {
513                name: "fn",
514                typ: "fun(acc: U, item: T): U",
515                description: "Reducer function",
516                optional: false,
517            },
518        ],
519        returns: "U",
520        generic_return: None,
521    },
522    // rs.ops.par - Parallel Collection Operations
523    LuaFunction {
524        name: "map",
525        module: Some("ops.par"),
526        description: "Parallel map with optional context",
527        params: &[
528            LuaParam {
529                name: "items",
530                typ: "T[]",
531                description: "Items to transform",
532                optional: false,
533            },
534            LuaParam {
535                name: "fn",
536                typ: "fun(item: T, ctx: table?): U",
537                description: "Transform function",
538                optional: false,
539            },
540            LuaParam {
541                name: "ctx",
542                typ: "table",
543                description: "Context passed to each call",
544                optional: true,
545            },
546        ],
547        returns: "U[]",
548        generic_return: None,
549    },
550    LuaFunction {
551        name: "filter",
552        module: Some("ops.par"),
553        description: "Parallel filter with optional context",
554        params: &[
555            LuaParam {
556                name: "items",
557                typ: "T[]",
558                description: "Items to filter",
559                optional: false,
560            },
561            LuaParam {
562                name: "fn",
563                typ: "fun(item: T, ctx: table?): boolean",
564                description: "Predicate function",
565                optional: false,
566            },
567            LuaParam {
568                name: "ctx",
569                typ: "table",
570                description: "Context passed to each call",
571                optional: true,
572            },
573        ],
574        returns: "T[]",
575        generic_return: None,
576    },
577    // ========================================================================
578    // rs.fs - File System Operations
579    // ========================================================================
580    LuaFunction {
581        name: "read",
582        module: Some("fs"),
583        description: "Read file contents as string",
584        params: &[LuaParam {
585            name: "path",
586            typ: "string",
587            description: "Path to file",
588            optional: false,
589        }],
590        returns: "string|nil",
591        generic_return: None,
592    },
593    LuaFunction {
594        name: "write",
595        module: Some("fs"),
596        description: "Write content to file",
597        params: &[
598            LuaParam {
599                name: "path",
600                typ: "string",
601                description: "Path to write to",
602                optional: false,
603            },
604            LuaParam {
605                name: "content",
606                typ: "string",
607                description: "Content to write",
608                optional: false,
609            },
610        ],
611        returns: "boolean",
612        generic_return: None,
613    },
614    LuaFunction {
615        name: "copy",
616        module: Some("fs"),
617        description: "Copy a file (works with binary files)",
618        params: &[
619            LuaParam {
620                name: "src",
621                typ: "string",
622                description: "Source file path",
623                optional: false,
624            },
625            LuaParam {
626                name: "dest",
627                typ: "string",
628                description: "Destination file path",
629                optional: false,
630            },
631        ],
632        returns: "boolean",
633        generic_return: None,
634    },
635    LuaFunction {
636        name: "exists",
637        module: Some("fs"),
638        description: "Check if file exists",
639        params: &[LuaParam {
640            name: "path",
641            typ: "string",
642            description: "Path to check",
643            optional: false,
644        }],
645        returns: "boolean",
646        generic_return: None,
647    },
648    LuaFunction {
649        name: "list",
650        module: Some("fs"),
651        description: "List files in directory matching pattern",
652        params: &[
653            LuaParam {
654                name: "path",
655                typ: "string",
656                description: "Directory to search",
657                optional: false,
658            },
659            LuaParam {
660                name: "pattern",
661                typ: "string",
662                description: "Glob pattern (default: '*')",
663                optional: true,
664            },
665        ],
666        returns: "FileInfo[]",
667        generic_return: None,
668    },
669    LuaFunction {
670        name: "list_dirs",
671        module: Some("fs"),
672        description: "List subdirectories",
673        params: &[LuaParam {
674            name: "path",
675            typ: "string",
676            description: "Directory to search",
677            optional: false,
678        }],
679        returns: "string[]",
680        generic_return: None,
681    },
682    LuaFunction {
683        name: "glob",
684        module: Some("fs"),
685        description: "Find files matching glob pattern",
686        params: &[LuaParam {
687            name: "pattern",
688            typ: "string",
689            description: "Glob pattern (e.g., '**/*.md')",
690            optional: false,
691        }],
692        returns: "FileInfo[]",
693        generic_return: None,
694    },
695    LuaFunction {
696        name: "scan",
697        module: Some("fs"),
698        description: "List directories in path",
699        params: &[LuaParam {
700            name: "path",
701            typ: "string",
702            description: "Directory to scan",
703            optional: false,
704        }],
705        returns: "FileInfo[]",
706        generic_return: None,
707    },
708    // rs.fs.par - Parallel File Operations
709    LuaFunction {
710        name: "read",
711        module: Some("fs.par"),
712        description: "Read multiple files in parallel",
713        params: &[LuaParam {
714            name: "paths",
715            typ: "string[]",
716            description: "Paths to read",
717            optional: false,
718        }],
719        returns: "(string|nil)[]",
720        generic_return: None,
721    },
722    LuaFunction {
723        name: "exists",
724        module: Some("fs.par"),
725        description: "Check multiple files exist in parallel",
726        params: &[LuaParam {
727            name: "paths",
728            typ: "string[]",
729            description: "Paths to check",
730            optional: false,
731        }],
732        returns: "boolean[]",
733        generic_return: None,
734    },
735    LuaFunction {
736        name: "copy",
737        module: Some("fs.par"),
738        description: "Copy multiple files in parallel",
739        params: &[
740            LuaParam {
741                name: "sources",
742                typ: "string[]",
743                description: "Source paths",
744                optional: false,
745            },
746            LuaParam {
747                name: "dests",
748                typ: "string[]",
749                description: "Destination paths",
750                optional: false,
751            },
752        ],
753        returns: "(boolean|string)[]",
754        generic_return: None,
755    },
756    LuaFunction {
757        name: "create_dirs",
758        module: Some("fs.par"),
759        description: "Create multiple directories in parallel",
760        params: &[LuaParam {
761            name: "paths",
762            typ: "string[]",
763            description: "Directory paths to create",
764            optional: false,
765        }],
766        returns: "(boolean|string)[]",
767        generic_return: None,
768    },
769    // ========================================================================
770    // rs.data - Data Loading
771    // ========================================================================
772    LuaFunction {
773        name: "load_json",
774        module: Some("data"),
775        description: "Load and parse JSON file",
776        params: &[LuaParam {
777            name: "path",
778            typ: "string",
779            description: "Path to JSON file",
780            optional: false,
781        }],
782        returns: "table|nil",
783        generic_return: None,
784    },
785    LuaFunction {
786        name: "load_yaml",
787        module: Some("data"),
788        description: "Load and parse YAML file",
789        params: &[LuaParam {
790            name: "path",
791            typ: "string",
792            description: "Path to YAML file",
793            optional: false,
794        }],
795        returns: "table|nil",
796        generic_return: None,
797    },
798    LuaFunction {
799        name: "load_toml",
800        module: Some("data"),
801        description: "Load and parse TOML file",
802        params: &[LuaParam {
803            name: "path",
804            typ: "string",
805            description: "Path to TOML file",
806            optional: false,
807        }],
808        returns: "table|nil",
809        generic_return: None,
810    },
811    LuaFunction {
812        name: "load_frontmatter",
813        module: Some("data"),
814        description: "Read and parse frontmatter from markdown file",
815        params: &[LuaParam {
816            name: "path",
817            typ: "string",
818            description: "Path to markdown file",
819            optional: false,
820        }],
821        returns: "FrontmatterResult|nil",
822        generic_return: None,
823    },
824    LuaFunction {
825        name: "from_json",
826        module: Some("data"),
827        description: "Parse JSON string to Lua value",
828        params: &[LuaParam {
829            name: "str",
830            typ: "string",
831            description: "JSON string",
832            optional: false,
833        }],
834        returns: "any",
835        generic_return: None,
836    },
837    LuaFunction {
838        name: "to_json",
839        module: Some("data"),
840        description: "Serialize Lua value to JSON string",
841        params: &[
842            LuaParam {
843                name: "value",
844                typ: "any",
845                description: "Value to serialize",
846                optional: false,
847            },
848            LuaParam {
849                name: "pretty",
850                typ: "boolean",
851                description: "Pretty print",
852                optional: true,
853            },
854        ],
855        returns: "string",
856        generic_return: None,
857    },
858    LuaFunction {
859        name: "from_yaml",
860        module: Some("data"),
861        description: "Parse YAML string to Lua value",
862        params: &[LuaParam {
863            name: "str",
864            typ: "string",
865            description: "YAML string",
866            optional: false,
867        }],
868        returns: "any",
869        generic_return: None,
870    },
871    LuaFunction {
872        name: "to_yaml",
873        module: Some("data"),
874        description: "Serialize Lua value to YAML string",
875        params: &[LuaParam {
876            name: "value",
877            typ: "any",
878            description: "Value to serialize",
879            optional: false,
880        }],
881        returns: "string",
882        generic_return: None,
883    },
884    LuaFunction {
885        name: "from_toml",
886        module: Some("data"),
887        description: "Parse TOML string to Lua value",
888        params: &[LuaParam {
889            name: "str",
890            typ: "string",
891            description: "TOML string",
892            optional: false,
893        }],
894        returns: "any",
895        generic_return: None,
896    },
897    LuaFunction {
898        name: "to_toml",
899        module: Some("data"),
900        description: "Serialize Lua value to TOML string",
901        params: &[LuaParam {
902            name: "value",
903            typ: "any",
904            description: "Value to serialize",
905            optional: false,
906        }],
907        returns: "string",
908        generic_return: None,
909    },
910    // rs.data.par - Parallel Data Loading
911    LuaFunction {
912        name: "load_json",
913        module: Some("data.par"),
914        description: "Load multiple JSON files in parallel",
915        params: &[LuaParam {
916            name: "paths",
917            typ: "string[]",
918            description: "Paths to JSON files",
919            optional: false,
920        }],
921        returns: "(table|nil)[]",
922        generic_return: None,
923    },
924    LuaFunction {
925        name: "load_yaml",
926        module: Some("data.par"),
927        description: "Load multiple YAML files in parallel",
928        params: &[LuaParam {
929            name: "paths",
930            typ: "string[]",
931            description: "Paths to YAML files",
932            optional: false,
933        }],
934        returns: "(table|nil)[]",
935        generic_return: None,
936    },
937    LuaFunction {
938        name: "load_frontmatter",
939        module: Some("data.par"),
940        description: "Parse frontmatter from multiple files in parallel",
941        params: &[LuaParam {
942            name: "paths",
943            typ: "string[]",
944            description: "Paths to markdown files",
945            optional: false,
946        }],
947        returns: "(FrontmatterResult|nil)[]",
948        generic_return: None,
949    },
950    // ========================================================================
951    // rs.image - Image Processing
952    // ========================================================================
953    LuaFunction {
954        name: "dimensions",
955        module: Some("image"),
956        description: "Get image width and height",
957        params: &[LuaParam {
958            name: "path",
959            typ: "string",
960            description: "Path to image",
961            optional: false,
962        }],
963        returns: "ImageDimensions|nil",
964        generic_return: None,
965    },
966    LuaFunction {
967        name: "resize",
968        module: Some("image"),
969        description: "Resize image",
970        params: &[
971            LuaParam {
972                name: "input",
973                typ: "string",
974                description: "Input path",
975                optional: false,
976            },
977            LuaParam {
978                name: "output",
979                typ: "string",
980                description: "Output path",
981                optional: false,
982            },
983            LuaParam {
984                name: "opts",
985                typ: "{ width: number, height?: number, quality?: number }",
986                description: "Resize options",
987                optional: false,
988            },
989        ],
990        returns: "boolean",
991        generic_return: None,
992    },
993    LuaFunction {
994        name: "convert",
995        module: Some("image"),
996        description: "Convert image format",
997        params: &[
998            LuaParam {
999                name: "input",
1000                typ: "string",
1001                description: "Input path",
1002                optional: false,
1003            },
1004            LuaParam {
1005                name: "output",
1006                typ: "string",
1007                description: "Output path",
1008                optional: false,
1009            },
1010            LuaParam {
1011                name: "opts",
1012                typ: "{ format?: string, quality?: number }",
1013                description: "Convert options",
1014                optional: true,
1015            },
1016        ],
1017        returns: "boolean",
1018        generic_return: None,
1019    },
1020    LuaFunction {
1021        name: "optimize",
1022        module: Some("image"),
1023        description: "Optimize/compress image",
1024        params: &[
1025            LuaParam {
1026                name: "input",
1027                typ: "string",
1028                description: "Input path",
1029                optional: false,
1030            },
1031            LuaParam {
1032                name: "output",
1033                typ: "string",
1034                description: "Output path",
1035                optional: false,
1036            },
1037            LuaParam {
1038                name: "opts",
1039                typ: "{ quality?: number }",
1040                description: "Optimize options",
1041                optional: true,
1042            },
1043        ],
1044        returns: "boolean",
1045        generic_return: None,
1046    },
1047    // rs.image.par - Parallel Image Processing
1048    LuaFunction {
1049        name: "resize",
1050        module: Some("image.par"),
1051        description: "Resize multiple images in parallel",
1052        params: &[
1053            LuaParam {
1054                name: "inputs",
1055                typ: "string[]",
1056                description: "Input paths",
1057                optional: false,
1058            },
1059            LuaParam {
1060                name: "outputs",
1061                typ: "string[]",
1062                description: "Output paths",
1063                optional: false,
1064            },
1065            LuaParam {
1066                name: "opts",
1067                typ: "{ width: number, height?: number, quality?: number }",
1068                description: "Resize options",
1069                optional: false,
1070            },
1071        ],
1072        returns: "(boolean|string)[]",
1073        generic_return: None,
1074    },
1075    LuaFunction {
1076        name: "convert",
1077        module: Some("image.par"),
1078        description: "Convert multiple images in parallel",
1079        params: &[
1080            LuaParam {
1081                name: "inputs",
1082                typ: "string[]",
1083                description: "Input paths",
1084                optional: false,
1085            },
1086            LuaParam {
1087                name: "outputs",
1088                typ: "string[]",
1089                description: "Output paths",
1090                optional: false,
1091            },
1092            LuaParam {
1093                name: "opts",
1094                typ: "{ quality?: number }",
1095                description: "Convert options",
1096                optional: true,
1097            },
1098        ],
1099        returns: "(boolean|string)[]",
1100        generic_return: None,
1101    },
1102    LuaFunction {
1103        name: "optimize",
1104        module: Some("image.par"),
1105        description: "Optimize multiple images in parallel",
1106        params: &[
1107            LuaParam {
1108                name: "inputs",
1109                typ: "string[]",
1110                description: "Input paths",
1111                optional: false,
1112            },
1113            LuaParam {
1114                name: "outputs",
1115                typ: "string[]",
1116                description: "Output paths",
1117                optional: false,
1118            },
1119            LuaParam {
1120                name: "opts",
1121                typ: "{ quality?: number }",
1122                description: "Optimize options",
1123                optional: true,
1124            },
1125        ],
1126        returns: "(boolean|string)[]",
1127        generic_return: None,
1128    },
1129    // ========================================================================
1130    // rs.text - Text Operations
1131    // ========================================================================
1132    LuaFunction {
1133        name: "slugify",
1134        module: Some("text"),
1135        description: "Convert text to URL-friendly slug",
1136        params: &[LuaParam {
1137            name: "text",
1138            typ: "string",
1139            description: "Text to slugify",
1140            optional: false,
1141        }],
1142        returns: "string",
1143        generic_return: None,
1144    },
1145    LuaFunction {
1146        name: "word_count",
1147        module: Some("text"),
1148        description: "Count words in text",
1149        params: &[LuaParam {
1150            name: "text",
1151            typ: "string",
1152            description: "Text to count",
1153            optional: false,
1154        }],
1155        returns: "number",
1156        generic_return: None,
1157    },
1158    LuaFunction {
1159        name: "reading_time",
1160        module: Some("text"),
1161        description: "Calculate reading time in minutes",
1162        params: &[
1163            LuaParam {
1164                name: "text",
1165                typ: "string",
1166                description: "Text to analyze",
1167                optional: false,
1168            },
1169            LuaParam {
1170                name: "wpm",
1171                typ: "number",
1172                description: "Words per minute (default: 200)",
1173                optional: true,
1174            },
1175        ],
1176        returns: "number",
1177        generic_return: None,
1178    },
1179    LuaFunction {
1180        name: "truncate",
1181        module: Some("text"),
1182        description: "Truncate text with optional suffix",
1183        params: &[
1184            LuaParam {
1185                name: "text",
1186                typ: "string",
1187                description: "Text to truncate",
1188                optional: false,
1189            },
1190            LuaParam {
1191                name: "len",
1192                typ: "number",
1193                description: "Maximum length",
1194                optional: false,
1195            },
1196            LuaParam {
1197                name: "suffix",
1198                typ: "string",
1199                description: "Suffix (default: '...')",
1200                optional: true,
1201            },
1202        ],
1203        returns: "string",
1204        generic_return: None,
1205    },
1206    LuaFunction {
1207        name: "url_encode",
1208        module: Some("text"),
1209        description: "URL encode a string",
1210        params: &[LuaParam {
1211            name: "text",
1212            typ: "string",
1213            description: "Text to encode",
1214            optional: false,
1215        }],
1216        returns: "string",
1217        generic_return: None,
1218    },
1219    LuaFunction {
1220        name: "url_decode",
1221        module: Some("text"),
1222        description: "URL decode a string",
1223        params: &[LuaParam {
1224            name: "text",
1225            typ: "string",
1226            description: "Text to decode",
1227            optional: false,
1228        }],
1229        returns: "string",
1230        generic_return: None,
1231    },
1232    // ========================================================================
1233    // rs.date - Date Operations
1234    // ========================================================================
1235    LuaFunction {
1236        name: "format",
1237        module: Some("date"),
1238        description: "Format a date string",
1239        params: &[
1240            LuaParam {
1241                name: "date",
1242                typ: "string|{ year: number, month: number, day: number }",
1243                description: "Date to format",
1244                optional: false,
1245            },
1246            LuaParam {
1247                name: "format",
1248                typ: "string",
1249                description: "Format string (strftime)",
1250                optional: false,
1251            },
1252        ],
1253        returns: "string|nil",
1254        generic_return: None,
1255    },
1256    LuaFunction {
1257        name: "parse",
1258        module: Some("date"),
1259        description: "Parse date string to table",
1260        params: &[LuaParam {
1261            name: "str",
1262            typ: "string",
1263            description: "Date string to parse",
1264            optional: false,
1265        }],
1266        returns: "{ year: number, month: number, day: number }|nil",
1267        generic_return: None,
1268    },
1269    LuaFunction {
1270        name: "rss_format",
1271        module: Some("date"),
1272        description: "Format date for RSS feeds (RFC 2822)",
1273        params: &[LuaParam {
1274            name: "date",
1275            typ: "string|{ year: number, month: number, day: number }",
1276            description: "Date to format",
1277            optional: false,
1278        }],
1279        returns: "string|nil",
1280        generic_return: None,
1281    },
1282    // ========================================================================
1283    // rs.path - Path Operations
1284    // ========================================================================
1285    LuaFunction {
1286        name: "join",
1287        module: Some("path"),
1288        description: "Join path segments",
1289        params: &[LuaParam {
1290            name: "...",
1291            typ: "string",
1292            description: "Path segments",
1293            optional: false,
1294        }],
1295        returns: "string",
1296        generic_return: None,
1297    },
1298    LuaFunction {
1299        name: "basename",
1300        module: Some("path"),
1301        description: "Get file name from path",
1302        params: &[LuaParam {
1303            name: "path",
1304            typ: "string",
1305            description: "Path",
1306            optional: false,
1307        }],
1308        returns: "string",
1309        generic_return: None,
1310    },
1311    LuaFunction {
1312        name: "dirname",
1313        module: Some("path"),
1314        description: "Get directory from path",
1315        params: &[LuaParam {
1316            name: "path",
1317            typ: "string",
1318            description: "Path",
1319            optional: false,
1320        }],
1321        returns: "string",
1322        generic_return: None,
1323    },
1324    LuaFunction {
1325        name: "extension",
1326        module: Some("path"),
1327        description: "Get file extension",
1328        params: &[LuaParam {
1329            name: "path",
1330            typ: "string",
1331            description: "Path",
1332            optional: false,
1333        }],
1334        returns: "string",
1335        generic_return: None,
1336    },
1337    // ========================================================================
1338    // rs.hash - Hash Operations
1339    // ========================================================================
1340    LuaFunction {
1341        name: "content",
1342        module: Some("hash"),
1343        description: "Hash string content (xxHash64)",
1344        params: &[LuaParam {
1345            name: "content",
1346            typ: "string",
1347            description: "Content to hash",
1348            optional: false,
1349        }],
1350        returns: "string",
1351        generic_return: None,
1352    },
1353    LuaFunction {
1354        name: "file",
1355        module: Some("hash"),
1356        description: "Hash file contents",
1357        params: &[LuaParam {
1358            name: "path",
1359            typ: "string",
1360            description: "Path to file",
1361            optional: false,
1362        }],
1363        returns: "string|nil",
1364        generic_return: None,
1365    },
1366    // ========================================================================
1367    // rs.git - Git Operations
1368    // ========================================================================
1369    LuaFunction {
1370        name: "info",
1371        module: Some("git"),
1372        description: "Get git info for repo or file",
1373        params: &[LuaParam {
1374            name: "path",
1375            typ: "string",
1376            description: "Path to file/directory (optional, defaults to repo)",
1377            optional: true,
1378        }],
1379        returns: "GitInfo|nil",
1380        generic_return: None,
1381    },
1382    LuaFunction {
1383        name: "is_ignored",
1384        module: Some("git"),
1385        description: "Check if path is ignored by .gitignore",
1386        params: &[LuaParam {
1387            name: "path",
1388            typ: "string",
1389            description: "Path to check",
1390            optional: false,
1391        }],
1392        returns: "boolean",
1393        generic_return: None,
1394    },
1395    // ========================================================================
1396    // rs.html - HTML Operations
1397    // ========================================================================
1398    LuaFunction {
1399        name: "to_text",
1400        module: Some("html"),
1401        description: "Convert HTML to plain text",
1402        params: &[LuaParam {
1403            name: "html",
1404            typ: "string",
1405            description: "HTML content",
1406            optional: false,
1407        }],
1408        returns: "string",
1409        generic_return: None,
1410    },
1411    LuaFunction {
1412        name: "strip_tags",
1413        module: Some("html"),
1414        description: "Remove HTML tags",
1415        params: &[LuaParam {
1416            name: "html",
1417            typ: "string",
1418            description: "HTML content",
1419            optional: false,
1420        }],
1421        returns: "string",
1422        generic_return: None,
1423    },
1424    LuaFunction {
1425        name: "extract_links",
1426        module: Some("html"),
1427        description: "Extract links from HTML",
1428        params: &[LuaParam {
1429            name: "html",
1430            typ: "string",
1431            description: "HTML content",
1432            optional: false,
1433        }],
1434        returns: "string[]",
1435        generic_return: None,
1436    },
1437    LuaFunction {
1438        name: "extract_images",
1439        module: Some("html"),
1440        description: "Extract image paths from HTML",
1441        params: &[LuaParam {
1442            name: "html",
1443            typ: "string",
1444            description: "HTML content",
1445            optional: false,
1446        }],
1447        returns: "string[]",
1448        generic_return: None,
1449    },
1450    // ========================================================================
1451    // rs.log - Logging
1452    // ========================================================================
1453    LuaFunction {
1454        name: "trace",
1455        module: Some("log"),
1456        description: "Log at trace level",
1457        params: &[LuaParam {
1458            name: "...",
1459            typ: "string",
1460            description: "Messages to log",
1461            optional: false,
1462        }],
1463        returns: "nil",
1464        generic_return: None,
1465    },
1466    LuaFunction {
1467        name: "debug",
1468        module: Some("log"),
1469        description: "Log at debug level",
1470        params: &[LuaParam {
1471            name: "...",
1472            typ: "string",
1473            description: "Messages to log",
1474            optional: false,
1475        }],
1476        returns: "nil",
1477        generic_return: None,
1478    },
1479    LuaFunction {
1480        name: "info",
1481        module: Some("log"),
1482        description: "Log at info level",
1483        params: &[LuaParam {
1484            name: "...",
1485            typ: "string",
1486            description: "Messages to log",
1487            optional: false,
1488        }],
1489        returns: "nil",
1490        generic_return: None,
1491    },
1492    LuaFunction {
1493        name: "warn",
1494        module: Some("log"),
1495        description: "Log at warn level",
1496        params: &[LuaParam {
1497            name: "...",
1498            typ: "string",
1499            description: "Messages to log",
1500            optional: false,
1501        }],
1502        returns: "nil",
1503        generic_return: None,
1504    },
1505    LuaFunction {
1506        name: "error",
1507        module: Some("log"),
1508        description: "Log at error level",
1509        params: &[LuaParam {
1510            name: "...",
1511            typ: "string",
1512            description: "Messages to log",
1513            optional: false,
1514        }],
1515        returns: "nil",
1516        generic_return: None,
1517    },
1518    LuaFunction {
1519        name: "print",
1520        module: Some("log"),
1521        description: "Log message (always visible)",
1522        params: &[LuaParam {
1523            name: "...",
1524            typ: "string",
1525            description: "Messages to log",
1526            optional: false,
1527        }],
1528        returns: "nil",
1529        generic_return: None,
1530    },
1531    // ========================================================================
1532    // rs.env - Environment
1533    // ========================================================================
1534    LuaFunction {
1535        name: "get",
1536        module: Some("env"),
1537        description: "Get environment variable with optional default value",
1538        params: &[
1539            LuaParam {
1540                name: "name",
1541                typ: "string",
1542                description: "Variable name",
1543                optional: false,
1544            },
1545            LuaParam {
1546                name: "default",
1547                typ: "string",
1548                description: "Default value if variable is not set",
1549                optional: true,
1550            },
1551        ],
1552        returns: "string|nil",
1553        generic_return: None,
1554    },
1555    // ========================================================================
1556    // rs.markdown - Markdown Processing
1557    // ========================================================================
1558    // plugins sub-module (callable table)
1559    LuaFunction {
1560        name: "default",
1561        module: Some("markdown.plugins"),
1562        description: "Get default markdown plugins",
1563        params: &[LuaParam {
1564            name: "opts",
1565            typ: "{ lazy_images?: boolean, heading_anchors?: boolean, external_links?: boolean }",
1566            description: "Options to disable specific plugins",
1567            optional: true,
1568        }],
1569        returns: "function[]",
1570        generic_return: None,
1571    },
1572    LuaFunction {
1573        name: "lazy_images",
1574        module: Some("markdown.plugins"),
1575        description: "Plugin for lazy-loading images",
1576        params: &[LuaParam {
1577            name: "opts",
1578            typ: "table",
1579            description: "Plugin options",
1580            optional: true,
1581        }],
1582        returns: "function",
1583        generic_return: None,
1584    },
1585    LuaFunction {
1586        name: "heading_anchors",
1587        module: Some("markdown.plugins"),
1588        description: "Plugin for adding heading anchor IDs",
1589        params: &[LuaParam {
1590            name: "opts",
1591            typ: "table",
1592            description: "Plugin options",
1593            optional: true,
1594        }],
1595        returns: "function",
1596        generic_return: None,
1597    },
1598    LuaFunction {
1599        name: "external_links",
1600        module: Some("markdown.plugins"),
1601        description: "Plugin for external link attributes",
1602        params: &[LuaParam {
1603            name: "opts",
1604            typ: "table",
1605            description: "Plugin options",
1606            optional: true,
1607        }],
1608        returns: "function",
1609        generic_return: None,
1610    },
1611    LuaFunction {
1612        name: "render",
1613        module: Some("markdown"),
1614        description: "Render markdown to HTML",
1615        params: &[
1616            LuaParam {
1617                name: "content",
1618                typ: "string",
1619                description: "Markdown content",
1620                optional: false,
1621            },
1622            LuaParam {
1623                name: "opts",
1624                typ: "{ plugins?: function[] }",
1625                description: "Render options",
1626                optional: true,
1627            },
1628        ],
1629        returns: "string",
1630        generic_return: None,
1631    },
1632    LuaFunction {
1633        name: "extract_links",
1634        module: Some("markdown"),
1635        description: "Extract links from markdown",
1636        params: &[LuaParam {
1637            name: "content",
1638            typ: "string",
1639            description: "Markdown content",
1640            optional: false,
1641        }],
1642        returns: "string[]",
1643        generic_return: None,
1644    },
1645    LuaFunction {
1646        name: "extract_images",
1647        module: Some("markdown"),
1648        description: "Extract image paths from markdown",
1649        params: &[LuaParam {
1650            name: "content",
1651            typ: "string",
1652            description: "Markdown content",
1653            optional: false,
1654        }],
1655        returns: "string[]",
1656        generic_return: None,
1657    },
1658    // ========================================================================
1659    // rs.assets - Asset Hashing
1660    // ========================================================================
1661    LuaFunction {
1662        name: "hash",
1663        module: Some("assets"),
1664        description: "Compute hash of content, returns task for await",
1665        params: &[
1666            LuaParam {
1667                name: "content",
1668                typ: "string",
1669                description: "Content to hash",
1670                optional: false,
1671            },
1672            LuaParam {
1673                name: "length",
1674                typ: "number",
1675                description: "Hash length (default: 8)",
1676                optional: true,
1677            },
1678        ],
1679        returns: "AsyncIOTask",
1680        generic_return: Some("string"),
1681    },
1682    LuaFunction {
1683        name: "hash_sync",
1684        module: Some("assets"),
1685        description: "Compute hash of content synchronously",
1686        params: &[
1687            LuaParam {
1688                name: "content",
1689                typ: "string",
1690                description: "Content to hash",
1691                optional: false,
1692            },
1693            LuaParam {
1694                name: "length",
1695                typ: "number",
1696                description: "Hash length (default: 8)",
1697                optional: true,
1698            },
1699        ],
1700        returns: "string",
1701        generic_return: None,
1702    },
1703    LuaFunction {
1704        name: "write_hashed",
1705        module: Some("assets"),
1706        description: "Write content with hashed filename (async)",
1707        params: &[
1708            LuaParam {
1709                name: "content",
1710                typ: "string",
1711                description: "Content to write",
1712                optional: false,
1713            },
1714            LuaParam {
1715                name: "path",
1716                typ: "string",
1717                description: "Output path",
1718                optional: false,
1719            },
1720            LuaParam {
1721                name: "opts",
1722                typ: "{ hash_length?: number }",
1723                description: "Options",
1724                optional: true,
1725            },
1726        ],
1727        returns: "AsyncIOTask",
1728        generic_return: Some("string"),
1729    },
1730    LuaFunction {
1731        name: "get_path",
1732        module: Some("assets"),
1733        description: "Get hashed path for original",
1734        params: &[LuaParam {
1735            name: "path",
1736            typ: "string",
1737            description: "Original path",
1738            optional: false,
1739        }],
1740        returns: "string",
1741        generic_return: None,
1742    },
1743    LuaFunction {
1744        name: "register",
1745        module: Some("assets"),
1746        description: "Register a path mapping",
1747        params: &[
1748            LuaParam {
1749                name: "original",
1750                typ: "string",
1751                description: "Original path",
1752                optional: false,
1753            },
1754            LuaParam {
1755                name: "hashed",
1756                typ: "string",
1757                description: "Hashed path",
1758                optional: false,
1759            },
1760        ],
1761        returns: "nil",
1762        generic_return: None,
1763    },
1764    LuaFunction {
1765        name: "manifest",
1766        module: Some("assets"),
1767        description: "Get all asset mappings",
1768        params: &[],
1769        returns: "table<string, string>",
1770        generic_return: None,
1771    },
1772    LuaFunction {
1773        name: "clear",
1774        module: Some("assets"),
1775        description: "Clear the asset manifest",
1776        params: &[],
1777        returns: "nil",
1778        generic_return: None,
1779    },
1780    LuaFunction {
1781        name: "check_unused",
1782        module: Some("assets"),
1783        description: "Find assets not referenced in HTML/CSS",
1784        params: &[LuaParam {
1785            name: "output_dir",
1786            typ: "string",
1787            description: "Output directory to scan",
1788            optional: false,
1789        }],
1790        returns: "string[]",
1791        generic_return: None,
1792    },
1793    // ========================================================================
1794    // rs.js - JavaScript Processing
1795    // ========================================================================
1796    LuaFunction {
1797        name: "concat",
1798        module: Some("js"),
1799        description: "Concatenate JavaScript files (async)",
1800        params: &[
1801            LuaParam {
1802                name: "input",
1803                typ: "string|string[]",
1804                description: "Input path(s) or glob pattern",
1805                optional: false,
1806            },
1807            LuaParam {
1808                name: "output",
1809                typ: "string",
1810                description: "Output path",
1811                optional: false,
1812            },
1813            LuaParam {
1814                name: "opts",
1815                typ: "{ minify?: boolean }",
1816                description: "Options",
1817                optional: true,
1818            },
1819        ],
1820        returns: "AsyncIOTask",
1821        generic_return: Some("nil"),
1822    },
1823    LuaFunction {
1824        name: "bundle",
1825        module: Some("js"),
1826        description: "Bundle and minify JavaScript (async)",
1827        params: &[
1828            LuaParam {
1829                name: "input",
1830                typ: "string|string[]",
1831                description: "Input path(s)",
1832                optional: false,
1833            },
1834            LuaParam {
1835                name: "output",
1836                typ: "string",
1837                description: "Output path",
1838                optional: false,
1839            },
1840            LuaParam {
1841                name: "opts",
1842                typ: "{ minify?: boolean, treeshake?: boolean, format?: string }",
1843                description: "Options",
1844                optional: true,
1845            },
1846        ],
1847        returns: "AsyncIOTask",
1848        generic_return: Some("nil"),
1849    },
1850    // ========================================================================
1851    // rs.css - CSS Processing
1852    // ========================================================================
1853    LuaFunction {
1854        name: "concat",
1855        module: Some("css"),
1856        description: "Concatenate CSS files (async)",
1857        params: &[
1858            LuaParam {
1859                name: "input",
1860                typ: "string|string[]",
1861                description: "Input path(s) or glob pattern",
1862                optional: false,
1863            },
1864            LuaParam {
1865                name: "output",
1866                typ: "string",
1867                description: "Output path",
1868                optional: false,
1869            },
1870            LuaParam {
1871                name: "opts",
1872                typ: "{ minify?: boolean, purge?: boolean, safelist?: string[] }",
1873                description: "Options",
1874                optional: true,
1875            },
1876        ],
1877        returns: "AsyncIOTask",
1878        generic_return: Some("nil"),
1879    },
1880    LuaFunction {
1881        name: "bundle",
1882        module: Some("css"),
1883        description: "Bundle and minify CSS with LightningCSS (async)",
1884        params: &[
1885            LuaParam {
1886                name: "input",
1887                typ: "string|string[]",
1888                description: "Input path(s)",
1889                optional: false,
1890            },
1891            LuaParam {
1892                name: "output",
1893                typ: "string",
1894                description: "Output path",
1895                optional: false,
1896            },
1897            LuaParam {
1898                name: "opts",
1899                typ: "{ minify?: boolean, purge?: boolean, safelist?: string[] }",
1900                description: "Options",
1901                optional: true,
1902            },
1903        ],
1904        returns: "AsyncIOTask",
1905        generic_return: Some("nil"),
1906    },
1907    LuaFunction {
1908        name: "purge",
1909        module: Some("css"),
1910        description: "Purge unused CSS rules from a CSS file (async)",
1911        params: &[
1912            LuaParam {
1913                name: "css_path",
1914                typ: "string",
1915                description: "Path to CSS file",
1916                optional: false,
1917            },
1918            LuaParam {
1919                name: "options",
1920                typ: "{ safelist?: string[] }",
1921                description: "Purge options",
1922                optional: true,
1923            },
1924        ],
1925        returns: "AsyncIOTask",
1926        generic_return: Some("nil"),
1927    },
1928    LuaFunction {
1929        name: "critical",
1930        module: Some("css"),
1931        description: "Extract critical CSS for HTML content (async)",
1932        params: &[
1933            LuaParam {
1934                name: "html_content",
1935                typ: "string",
1936                description: "HTML content to analyze",
1937                optional: false,
1938            },
1939            LuaParam {
1940                name: "css_path",
1941                typ: "string",
1942                description: "Path to CSS file",
1943                optional: false,
1944            },
1945            LuaParam {
1946                name: "options",
1947                typ: "{ minify?: boolean, safelist?: string[] }",
1948                description: "Options",
1949                optional: true,
1950            },
1951        ],
1952        returns: "AsyncIOTask",
1953        generic_return: Some("string"),
1954    },
1955    LuaFunction {
1956        name: "inline_critical",
1957        module: Some("css"),
1958        description: "Inline critical CSS into HTML file (async)",
1959        params: &[
1960            LuaParam {
1961                name: "html_path",
1962                typ: "string",
1963                description: "Path to HTML file",
1964                optional: false,
1965            },
1966            LuaParam {
1967                name: "css_path",
1968                typ: "string",
1969                description: "Path to CSS file",
1970                optional: false,
1971            },
1972            LuaParam {
1973                name: "options",
1974                typ: "{ minify?: boolean, safelist?: string[], css_href?: string }",
1975                description: "Options",
1976                optional: true,
1977            },
1978        ],
1979        returns: "AsyncIOTask",
1980        generic_return: Some("nil"),
1981    },
1982    // ========================================================================
1983    // rs.fonts - Font Handling
1984    // ========================================================================
1985    LuaFunction {
1986        name: "download_google_font",
1987        module: Some("fonts"),
1988        description: "Download Google Font files (async)",
1989        params: &[
1990            LuaParam {
1991                name: "family",
1992                typ: "string",
1993                description: "Font family name",
1994                optional: false,
1995            },
1996            LuaParam {
1997                name: "options",
1998                typ: "{ fonts_dir: string, css_path: string, css_prefix?: string, weights?: number[], display?: string, cache?: boolean|string, minify?: boolean }",
1999                description: "Download options",
2000                optional: false,
2001            },
2002        ],
2003        returns: "AsyncIOTask",
2004        generic_return: Some("nil"),
2005    },
2006    // ========================================================================
2007    // rs.crypt - Encryption
2008    // ========================================================================
2009    LuaFunction {
2010        name: "encrypt",
2011        module: Some("crypt"),
2012        description: "Encrypt content with password",
2013        params: &[
2014            LuaParam {
2015                name: "content",
2016                typ: "string",
2017                description: "Content to encrypt",
2018                optional: false,
2019            },
2020            LuaParam {
2021                name: "password",
2022                typ: "string",
2023                description: "Encryption password",
2024                optional: true,
2025            },
2026        ],
2027        returns: "string",
2028        generic_return: None,
2029    },
2030    LuaFunction {
2031        name: "decrypt",
2032        module: Some("crypt"),
2033        description: "Decrypt content with password",
2034        params: &[
2035            LuaParam {
2036                name: "encrypted",
2037                typ: "string",
2038                description: "Encrypted content",
2039                optional: false,
2040            },
2041            LuaParam {
2042                name: "password",
2043                typ: "string",
2044                description: "Decryption password",
2045                optional: true,
2046            },
2047        ],
2048        returns: "string|nil",
2049        generic_return: None,
2050    },
2051    LuaFunction {
2052        name: "encrypt_html",
2053        module: Some("crypt"),
2054        description: "Encrypt HTML with embedded decryption",
2055        params: &[
2056            LuaParam {
2057                name: "html",
2058                typ: "string",
2059                description: "HTML to encrypt",
2060                optional: false,
2061            },
2062            LuaParam {
2063                name: "password",
2064                typ: "string",
2065                description: "Encryption password",
2066                optional: true,
2067            },
2068        ],
2069        returns: "string",
2070        generic_return: None,
2071    },
2072    // ========================================================================
2073    // rs.pwa - PWA Generation
2074    // ========================================================================
2075    LuaFunction {
2076        name: "manifest",
2077        module: Some("pwa"),
2078        description: "Generate PWA manifest.json (async)",
2079        params: &[LuaParam {
2080            name: "options",
2081            typ: "{ name: string, short_name: string, output: string, description?: string, start_url?: string, display?: string, background_color?: string, theme_color?: string, icons?: { src: string, sizes: string, type?: string, purpose?: string }[] }",
2082            description: "Manifest configuration",
2083            optional: false,
2084        }],
2085        returns: "AsyncIOTask",
2086        generic_return: Some("nil"),
2087    },
2088    LuaFunction {
2089        name: "service_worker",
2090        module: Some("pwa"),
2091        description: "Generate service worker (async)",
2092        params: &[LuaParam {
2093            name: "options",
2094            typ: "{ cache_name: string, output: string, version?: string, precache?: string[], network_first?: string[], cache_first?: string[], offline_page?: string }",
2095            description: "Service worker configuration",
2096            optional: false,
2097        }],
2098        returns: "AsyncIOTask",
2099        generic_return: Some("nil"),
2100    },
2101    // ========================================================================
2102    // rs.seo - SEO Generation
2103    // ========================================================================
2104    LuaFunction {
2105        name: "sitemap",
2106        module: Some("seo"),
2107        description: "Generate sitemap.xml (async)",
2108        params: &[LuaParam {
2109            name: "options",
2110            typ: "{ base_url: string, pages: (string | { path: string, lastmod?: string, changefreq?: string, priority?: number })[], output: string, default_changefreq?: string, default_priority?: number, exclude?: string[] }",
2111            description: "Sitemap configuration",
2112            optional: false,
2113        }],
2114        returns: "AsyncIOTask",
2115        generic_return: Some("nil"),
2116    },
2117    LuaFunction {
2118        name: "robots",
2119        module: Some("seo"),
2120        description: "Generate robots.txt (async)",
2121        params: &[LuaParam {
2122            name: "options",
2123            typ: "{ output: string, sitemap_url?: string, allow?: string[], disallow?: string[], user_agent?: string }",
2124            description: "Robots configuration",
2125            optional: false,
2126        }],
2127        returns: "AsyncIOTask",
2128        generic_return: Some("nil"),
2129    },
2130    // ========================================================================
2131    // rs.coro - Coroutines
2132    // ========================================================================
2133    LuaFunction {
2134        name: "task",
2135        module: Some("coro"),
2136        description: "Create a task from a function",
2137        params: &[LuaParam {
2138            name: "fn",
2139            typ: "function",
2140            description: "Function to run",
2141            optional: false,
2142        }],
2143        returns: "Task",
2144        generic_return: None,
2145    },
2146    LuaFunction {
2147        name: "await",
2148        module: Some("coro"),
2149        description: "Await a task result",
2150        params: &[LuaParam {
2151            name: "task",
2152            typ: "Task",
2153            description: "Task to await",
2154            optional: false,
2155        }],
2156        returns: "any",
2157        generic_return: None,
2158    },
2159    // ========================================================================
2160    // rs.parallel - Parallel Processing (legacy)
2161    // ========================================================================
2162    LuaFunction {
2163        name: "map",
2164        module: Some("parallel"),
2165        description: "Parallel map with optional context",
2166        params: &[
2167            LuaParam {
2168                name: "items",
2169                typ: "T[]",
2170                description: "Items to process",
2171                optional: false,
2172            },
2173            LuaParam {
2174                name: "fn",
2175                typ: "fun(item: T, ctx: table?): U",
2176                description: "Transform function",
2177                optional: false,
2178            },
2179            LuaParam {
2180                name: "ctx",
2181                typ: "table",
2182                description: "Context passed to each call",
2183                optional: true,
2184            },
2185        ],
2186        returns: "U[]",
2187        generic_return: None,
2188    },
2189    LuaFunction {
2190        name: "filter",
2191        module: Some("parallel"),
2192        description: "Parallel filter with optional context",
2193        params: &[
2194            LuaParam {
2195                name: "items",
2196                typ: "T[]",
2197                description: "Items to filter",
2198                optional: false,
2199            },
2200            LuaParam {
2201                name: "fn",
2202                typ: "fun(item: T, ctx: table?): boolean",
2203                description: "Predicate function",
2204                optional: false,
2205            },
2206            LuaParam {
2207                name: "ctx",
2208                typ: "table",
2209                description: "Context passed to each call",
2210                optional: true,
2211            },
2212        ],
2213        returns: "T[]",
2214        generic_return: None,
2215    },
2216    // ========================================================================
2217    // rs.async - Async I/O
2218    // ========================================================================
2219    LuaFunction {
2220        name: "fetch",
2221        module: Some("async"),
2222        description: "Fetch URL content (async)",
2223        params: &[
2224            LuaParam {
2225                name: "url",
2226                typ: "string",
2227                description: "URL to fetch",
2228                optional: false,
2229            },
2230            LuaParam {
2231                name: "opts",
2232                typ: "{ method?: string, headers?: table, body?: string, timeout?: number, cache?: boolean|string }",
2233                description: "Request options",
2234                optional: true,
2235            },
2236        ],
2237        returns: "AsyncTask",
2238        generic_return: Some("FetchResponse"),
2239    },
2240    LuaFunction {
2241        name: "fetch_sync",
2242        module: Some("async"),
2243        description: "Fetch URL content synchronously",
2244        params: &[
2245            LuaParam {
2246                name: "url",
2247                typ: "string",
2248                description: "URL to fetch",
2249                optional: false,
2250            },
2251            LuaParam {
2252                name: "opts",
2253                typ: "{ method?: string, headers?: table, body?: string, timeout?: number, cache?: boolean|string }",
2254                description: "Request options",
2255                optional: true,
2256            },
2257        ],
2258        returns: "FetchResponse",
2259        generic_return: None,
2260    },
2261    LuaFunction {
2262        name: "fetch_json",
2263        module: Some("async"),
2264        description: "Fetch and parse JSON",
2265        params: &[
2266            LuaParam {
2267                name: "url",
2268                typ: "string",
2269                description: "URL to fetch",
2270                optional: false,
2271            },
2272            LuaParam {
2273                name: "opts",
2274                typ: "{ method?: string, headers?: table, body?: string, timeout?: number }",
2275                description: "Request options",
2276                optional: true,
2277            },
2278        ],
2279        returns: "any",
2280        generic_return: None,
2281    },
2282    LuaFunction {
2283        name: "fetch_bytes",
2284        module: Some("async"),
2285        description: "Fetch binary data, returns task for await",
2286        params: &[
2287            LuaParam {
2288                name: "url",
2289                typ: "string",
2290                description: "URL to fetch",
2291                optional: false,
2292            },
2293            LuaParam {
2294                name: "opts",
2295                typ: "{ method?: string, headers?: table, body?: string, timeout?: number, cache?: boolean|string }",
2296                description: "Request options",
2297                optional: true,
2298            },
2299        ],
2300        returns: "AsyncTask",
2301        generic_return: Some("FetchResponse"),
2302    },
2303    LuaFunction {
2304        name: "fetch_bytes_sync",
2305        module: Some("async"),
2306        description: "Fetch binary data synchronously",
2307        params: &[
2308            LuaParam {
2309                name: "url",
2310                typ: "string",
2311                description: "URL to fetch",
2312                optional: false,
2313            },
2314            LuaParam {
2315                name: "opts",
2316                typ: "{ method?: string, headers?: table, body?: string, timeout?: number, cache?: boolean|string }",
2317                description: "Request options",
2318                optional: true,
2319            },
2320        ],
2321        returns: "{ status: number, ok: boolean, body: string }",
2322        generic_return: None,
2323    },
2324    LuaFunction {
2325        name: "fetch_all",
2326        module: Some("async"),
2327        description: "Fetch multiple URLs concurrently",
2328        params: &[LuaParam {
2329            name: "requests",
2330            typ: "(string | { url: string, options?: table })[]",
2331            description: "URLs or request objects",
2332            optional: false,
2333        }],
2334        returns: "FetchResponse[]",
2335        generic_return: None,
2336    },
2337    LuaFunction {
2338        name: "spawn",
2339        module: Some("async"),
2340        description: "Spawn a fetch task for later await",
2341        params: &[
2342            LuaParam {
2343                name: "url",
2344                typ: "string",
2345                description: "URL to fetch",
2346                optional: false,
2347            },
2348            LuaParam {
2349                name: "opts",
2350                typ: "{ method?: string, headers?: table, body?: string }",
2351                description: "Request options",
2352                optional: true,
2353            },
2354        ],
2355        returns: "AsyncTask",
2356        generic_return: Some("FetchResponse"),
2357    },
2358    LuaFunction {
2359        name: "wrap",
2360        module: Some("async"),
2361        description: "Wrap a Lua function for deferred execution",
2362        params: &[LuaParam {
2363            name: "fn",
2364            typ: "function",
2365            description: "Function to wrap",
2366            optional: false,
2367        }],
2368        returns: "AsyncLuaTask",
2369        generic_return: Some("T"),
2370    },
2371    LuaFunction {
2372        name: "await",
2373        module: Some("async"),
2374        description: "Await an async task",
2375        params: &[LuaParam {
2376            name: "task",
2377            typ: "AsyncTask|AsyncIOTask|AsyncLuaTask",
2378            description: "Task to await",
2379            optional: false,
2380        }],
2381        returns: "any",
2382        generic_return: None,
2383    },
2384    LuaFunction {
2385        name: "await_all",
2386        module: Some("async"),
2387        description: "Await multiple tasks concurrently",
2388        params: &[LuaParam {
2389            name: "tasks",
2390            typ: "(AsyncTask|AsyncIOTask|AsyncLuaTask)[]",
2391            description: "Tasks to await",
2392            optional: false,
2393        }],
2394        returns: "any[]",
2395        generic_return: None,
2396    },
2397    LuaFunction {
2398        name: "read_file",
2399        module: Some("async"),
2400        description: "Read text file, returns task for await",
2401        params: &[LuaParam {
2402            name: "path",
2403            typ: "string",
2404            description: "Path to file",
2405            optional: false,
2406        }],
2407        returns: "AsyncIOTask",
2408        generic_return: Some("string"),
2409    },
2410    LuaFunction {
2411        name: "read_files",
2412        module: Some("async"),
2413        description: "Read multiple files concurrently, returns task for await",
2414        params: &[LuaParam {
2415            name: "paths",
2416            typ: "string[]",
2417            description: "Paths to read",
2418            optional: false,
2419        }],
2420        returns: "AsyncIOTask",
2421        generic_return: Some("(string|nil)[]"),
2422    },
2423    LuaFunction {
2424        name: "write_file",
2425        module: Some("async"),
2426        description: "Write text file, returns task for await",
2427        params: &[
2428            LuaParam {
2429                name: "path",
2430                typ: "string",
2431                description: "Path to write",
2432                optional: false,
2433            },
2434            LuaParam {
2435                name: "content",
2436                typ: "string",
2437                description: "Content to write",
2438                optional: false,
2439            },
2440        ],
2441        returns: "AsyncIOTask",
2442        generic_return: Some("boolean"),
2443    },
2444    LuaFunction {
2445        name: "write",
2446        module: Some("async"),
2447        description: "Write binary file, returns task for await",
2448        params: &[
2449            LuaParam {
2450                name: "path",
2451                typ: "string",
2452                description: "Path to write",
2453                optional: false,
2454            },
2455            LuaParam {
2456                name: "data",
2457                typ: "string",
2458                description: "Binary data to write",
2459                optional: false,
2460            },
2461        ],
2462        returns: "AsyncIOTask",
2463        generic_return: Some("boolean"),
2464    },
2465    LuaFunction {
2466        name: "exists",
2467        module: Some("async"),
2468        description: "Check if path exists, returns task for await",
2469        params: &[LuaParam {
2470            name: "path",
2471            typ: "string",
2472            description: "Path to check",
2473            optional: false,
2474        }],
2475        returns: "AsyncIOTask",
2476        generic_return: Some("boolean"),
2477    },
2478    LuaFunction {
2479        name: "load_json",
2480        module: Some("async"),
2481        description: "Load and parse JSON file, returns task for await",
2482        params: &[LuaParam {
2483            name: "path",
2484            typ: "string",
2485            description: "Path to JSON file",
2486            optional: false,
2487        }],
2488        returns: "AsyncIOTask",
2489        generic_return: Some("any"),
2490    },
2491    LuaFunction {
2492        name: "copy_file",
2493        module: Some("async"),
2494        description: "Copy file, returns task for await",
2495        params: &[
2496            LuaParam {
2497                name: "src",
2498                typ: "string",
2499                description: "Source path",
2500                optional: false,
2501            },
2502            LuaParam {
2503                name: "dst",
2504                typ: "string",
2505                description: "Destination path",
2506                optional: false,
2507            },
2508        ],
2509        returns: "AsyncIOTask",
2510        generic_return: Some("number"),
2511    },
2512    LuaFunction {
2513        name: "rename",
2514        module: Some("async"),
2515        description: "Rename file or directory, returns task for await",
2516        params: &[
2517            LuaParam {
2518                name: "src",
2519                typ: "string",
2520                description: "Source path",
2521                optional: false,
2522            },
2523            LuaParam {
2524                name: "dst",
2525                typ: "string",
2526                description: "Destination path",
2527                optional: false,
2528            },
2529        ],
2530        returns: "AsyncIOTask",
2531        generic_return: Some("boolean"),
2532    },
2533    LuaFunction {
2534        name: "create_dir",
2535        module: Some("async"),
2536        description: "Create directory, returns task for await",
2537        params: &[LuaParam {
2538            name: "path",
2539            typ: "string",
2540            description: "Directory path",
2541            optional: false,
2542        }],
2543        returns: "AsyncIOTask",
2544        generic_return: Some("boolean"),
2545    },
2546    LuaFunction {
2547        name: "remove_file",
2548        module: Some("async"),
2549        description: "Remove file, returns task for await",
2550        params: &[LuaParam {
2551            name: "path",
2552            typ: "string",
2553            description: "File path",
2554            optional: false,
2555        }],
2556        returns: "AsyncIOTask",
2557        generic_return: Some("boolean"),
2558    },
2559    LuaFunction {
2560        name: "remove_dir",
2561        module: Some("async"),
2562        description: "Remove directory recursively, returns task for await",
2563        params: &[LuaParam {
2564            name: "path",
2565            typ: "string",
2566            description: "Directory path",
2567            optional: false,
2568        }],
2569        returns: "AsyncIOTask",
2570        generic_return: Some("boolean"),
2571    },
2572    LuaFunction {
2573        name: "metadata",
2574        module: Some("async"),
2575        description: "Get file metadata, returns task for await",
2576        params: &[LuaParam {
2577            name: "path",
2578            typ: "string",
2579            description: "Path to file/directory",
2580            optional: false,
2581        }],
2582        returns: "AsyncIOTask",
2583        generic_return: Some("FileMetadata"),
2584    },
2585    LuaFunction {
2586        name: "read_dir",
2587        module: Some("async"),
2588        description: "List directory contents, returns task for await",
2589        params: &[LuaParam {
2590            name: "path",
2591            typ: "string",
2592            description: "Directory path",
2593            optional: false,
2594        }],
2595        returns: "AsyncIOTask",
2596        generic_return: Some("DirEntry[]"),
2597    },
2598    LuaFunction {
2599        name: "canonicalize",
2600        module: Some("async"),
2601        description: "Get canonical/absolute path, returns task for await",
2602        params: &[LuaParam {
2603            name: "path",
2604            typ: "string",
2605            description: "Path to resolve",
2606            optional: false,
2607        }],
2608        returns: "AsyncIOTask",
2609        generic_return: Some("string"),
2610    },
2611];
2612
2613// ============================================================================
2614// DOCUMENTATION GENERATORS
2615// ============================================================================
2616
2617/// Generate EmmyLua annotations
2618pub fn generate_emmylua() -> String {
2619    let mut output = String::new();
2620    output.push_str("---@meta rs-web\n\n");
2621    output.push_str("-- Auto-generated EmmyLua annotations for rs-web\n\n");
2622
2623    // Generate class definitions
2624    for class in LUA_CLASSES {
2625        if class.is_generic {
2626            // Generic class with type parameter
2627            output.push_str(&format!("---@class {}<T>\n", class.name));
2628        } else {
2629            output.push_str(&format!("---@class {}\n", class.name));
2630        }
2631        for field in class.fields {
2632            output.push_str(&format!(
2633                "---@field {} {} {}\n",
2634                field.name, field.typ, field.description
2635            ));
2636        }
2637        output.push('\n');
2638    }
2639
2640    // Generate module structure
2641    output.push_str("---@class rs\n");
2642    output.push_str("local rs = {}\n\n");
2643
2644    // Group functions by module
2645    let mut modules: std::collections::HashMap<&str, Vec<&LuaFunction>> =
2646        std::collections::HashMap::new();
2647    for func in LUA_FUNCTIONS {
2648        let mod_name = func.module.unwrap_or("");
2649        modules.entry(mod_name).or_default().push(func);
2650    }
2651
2652    // Track declared modules to avoid duplicates
2653    let mut declared_modules: std::collections::HashSet<String> = std::collections::HashSet::new();
2654
2655    // Generate each module
2656    for (mod_name, funcs) in &modules {
2657        if mod_name.is_empty() {
2658            continue;
2659        }
2660
2661        let parts: Vec<&str> = mod_name.split('.').collect();
2662
2663        // Declare all parent modules first
2664        let mut current_path = String::new();
2665        for (i, part) in parts.iter().enumerate() {
2666            if i > 0 {
2667                current_path.push('.');
2668            }
2669            current_path.push_str(part);
2670
2671            if !declared_modules.contains(&current_path) {
2672                declared_modules.insert(current_path.clone());
2673                output.push_str(&format!("---@class rs.{}\n", current_path));
2674                output.push_str(&format!("rs.{} = {{}}\n\n", current_path));
2675            }
2676        }
2677
2678        for func in funcs {
2679            // Generate function documentation
2680            output.push_str(&format!("--- {}\n", func.description));
2681            for param in func.params {
2682                let optional = if param.optional { "?" } else { "" };
2683                output.push_str(&format!(
2684                    "---@param {}{} {} {}\n",
2685                    param.name, optional, param.typ, param.description
2686                ));
2687            }
2688
2689            // Handle generic return types
2690            let return_type = if let Some(inner_type) = func.generic_return {
2691                format!("{}<{}>", func.returns, inner_type)
2692            } else {
2693                func.returns.to_string()
2694            };
2695            output.push_str(&format!("---@return {}\n", return_type));
2696
2697            output.push_str(&format!("function rs.{}.{}(", mod_name, func.name));
2698            let param_names: Vec<&str> = func.params.iter().map(|p| p.name).collect();
2699            output.push_str(&param_names.join(", "));
2700            output.push_str(") end\n\n");
2701        }
2702    }
2703
2704    output.push_str("return rs\n");
2705    output
2706}
2707
2708/// Generate markdown documentation
2709pub fn generate_markdown() -> String {
2710    let mut output = String::new();
2711    output.push_str("# Lua API Reference\n\n");
2712
2713    // Group functions by module
2714    let mut modules: std::collections::BTreeMap<&str, Vec<&LuaFunction>> =
2715        std::collections::BTreeMap::new();
2716    for func in LUA_FUNCTIONS {
2717        let mod_name = func.module.unwrap_or("rs");
2718        modules.entry(mod_name).or_default().push(func);
2719    }
2720
2721    for (mod_name, funcs) in modules {
2722        output.push_str(&format!("## rs.{}\n\n", mod_name));
2723
2724        for func in funcs {
2725            output.push_str(&format!("### `rs.{}.{}`\n\n", mod_name, func.name));
2726            output.push_str(&format!("{}\n\n", func.description));
2727
2728            if !func.params.is_empty() {
2729                output.push_str("**Parameters:**\n\n");
2730                for param in func.params {
2731                    let optional = if param.optional { " (optional)" } else { "" };
2732                    output.push_str(&format!(
2733                        "- `{}`: `{}`{} - {}\n",
2734                        param.name, param.typ, optional, param.description
2735                    ));
2736                }
2737                output.push('\n');
2738            }
2739
2740            output.push_str(&format!("**Returns:** `{}`\n\n", func.returns));
2741        }
2742    }
2743
2744    output
2745}