Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design & Write language agnostic bindings format #247

Closed
Tracked by #245
makspll opened this issue Feb 2, 2025 · 1 comment · Fixed by #274
Closed
Tracked by #245

Design & Write language agnostic bindings format #247

makspll opened this issue Feb 2, 2025 · 1 comment · Fixed by #274
Milestone

Comments

@makspll
Copy link
Owner

makspll commented Feb 2, 2025

Given metadata and information about types functions and arguments, we should be able to produce "bindings" definition files, let's call them language agnostic definition files or LAD's.

These should contain everything we might need for generating:

  • documentation
  • language server definition files
  • lints

I am imagining something along the lines of:

{
 "types": [
   {
     "name": "MyType",
     "id": 1234
     "path": "my_crate::mod",
     "generics": ["T"],
     "docstring": "A type that does type things...",
     "methods": [
       0,4,6
     ],
     "fields": [
        ...
     ],
     "variants": [
       ...
    ]
   }
 ],
 "functions": [
    "name": "my_func",
    "path": "my_crate::mod::func",
    "docstring": "a function that does function things...",
    "arguments": [
        {
            "type": 1234,
            "name": "my_arg",
            "kind": "Ref"
        }
    ]
 ]
}
@makspll
Copy link
Owner Author

makspll commented Feb 11, 2025

So far given:

        #[derive(Reflect)]
        /// I am a struct
        struct StructType<T> {
            /// hello from field
            field: usize,
            /// hello from field 2
            field2: T,
        }

        #[derive(Reflect)]
        /// I am a unit test type
        struct UnitType;

        #[derive(Reflect)]
        /// I am a tuple test type
        struct TupleStructType(pub usize, #[doc = "hello"] pub String);

        #[derive(Reflect)]
        enum EnumType {
            /// hello from variant
            Unit,
            /// hello from variant 2
            Struct {
                /// hello from field
                field: usize,
            },
            /// hello from variant 3
            TupleStruct(usize, #[doc = "asd"] String),
        }

I have:

{
  "version": "0.1.0",
  "types": {
    "bevy_mod_scripting_core::docgen::ladfile::test::EnumType": {
      "identifier": "EnumType",
      "crate": "bevy_mod_scripting_core",
      "path": "bevy_mod_scripting_core::docgen::ladfile::test::EnumType",
      "layout": [
        {
          "kind": "Unit",
          "name": "Unit"
        },
        {
          "kind": "Struct",
          "name": "Struct",
          "fields": [
            {
              "name": "field",
              "type": "usize"
            }
          ]
        },
        {
          "kind": "TupleStruct",
          "name": "TupleStruct",
          "fields": [
            {
              "type": "usize"
            },
            {
              "type": "alloc::string::String"
            }
          ]
        }
      ]
    },
    "bevy_mod_scripting_core::docgen::ladfile::test::StructType<usize>": {
      "identifier": "StructType",
      "crate": "bevy_mod_scripting_core",
      "path": "bevy_mod_scripting_core::docgen::ladfile::test::StructType<usize>",
      "generics": [
        {
          "type_id": "usize",
          "name": "T"
        }
      ],
      "documentation": " I am a struct",
      "layout": {
        "kind": "Struct",
        "name": "StructType",
        "fields": [
          {
            "name": "field",
            "type": "usize"
          },
          {
            "name": "field2",
            "type": "usize"
          }
        ]
      }
    },
    "bevy_mod_scripting_core::docgen::ladfile::test::TupleStructType": {
      "identifier": "TupleStructType",
      "crate": "bevy_mod_scripting_core",
      "path": "bevy_mod_scripting_core::docgen::ladfile::test::TupleStructType",
      "documentation": " I am a tuple test type",
      "layout": {
        "kind": "TupleStruct",
        "name": "TupleStructType",
        "fields": [
          {
            "type": "usize"
          },
          {
            "type": "alloc::string::String"
          }
        ]
      }
    },
    "bevy_mod_scripting_core::docgen::ladfile::test::UnitType": {
      "identifier": "UnitType",
      "crate": "bevy_mod_scripting_core",
      "path": "bevy_mod_scripting_core::docgen::ladfile::test::UnitType",
      "documentation": " I am a unit test type",
      "layout": {
        "kind": "Struct",
        "name": "UnitType"
      }
    }
  },
  "functions": {
    "::hello_world": {
      "identifier": "hello_world",
      "arguments": [
        {
          "kind": {
            "primitive": "usize"
          },
          "name": "arg1"
        }
      ],
      "return_type": "usize"
    },
    "bevy_mod_scripting_core::docgen::ladfile::test::StructType<usize>::hello_world": {
      "identifier": "hello_world",
      "arguments": [
        {
          "kind": {
            "primitive": "reflectReference"
          },
          "name": "ref_"
        },
        {
          "kind": {
            "tuple": [
              {
                "primitive": "usize"
              },
              {
                "primitive": "string"
              }
            ]
          },
          "name": "tuple"
        },
        {
          "kind": {
            "option": {
              "vec": {
                "ref": "bevy_mod_scripting_core::docgen::ladfile::test::EnumType"
              }
            }
          },
          "name": "option_vec_ref_wrapper"
        }
      ],
      "return_type": "usize"
    }
  },
  "primitives": {
    "TypeId(0x0b36ea25c1cf517efce182c726ea2190)": {
      "kind": "pathBuf",
      "documentation": "A heap allocated file path"
    },
    "TypeId(0x1c306727557831f62320b5841ddc7eb3)": {
      "kind": "dynamicFunction",
      "documentation": "A callable dynamic function"
    },
    "TypeId(0x7adbf8cf2ed263727e95f06e821c8654)": {
      "kind": "osString",
      "documentation": "A heap allocated OS string"
    },
    "TypeId(0x7f945ad2d333d63863e3b6f35dfc0c5d)": {
      "kind": "dynamicFunctionMut",
      "documentation": "A stateful and callable dynamic function"
    },
    "TypeId(0xb98b1b7157a6417863eb502cd6cb5d6d)": {
      "kind": "str",
      "documentation": "A static string slice"
    },
    "alloc::string::String": {
      "kind": "string",
      "documentation": "A heap allocated string"
    },
    "bevy_mod_scripting_core::bindings::function::script_function::FunctionCallContext": {
      "kind": "functionCallContext",
      "documentation": "Function call context, if accepted by a function, means the function can access the world in arbitrary ways."
    },
    "bevy_mod_scripting_core::bindings::reference::ReflectReference": {
      "kind": "reflectReference",
      "documentation": "A reference to a reflectable type"
    },
    "bool": {
      "kind": "bool",
      "documentation": "A boolean value"
    },
    "char": {
      "kind": "char",
      "documentation": "An 8-bit character"
    },
    "f32": {
      "kind": "f32",
      "documentation": "A 32-bit floating point number"
    },
    "f64": {
      "kind": "f64",
      "documentation": "A 64-bit floating point number"
    },
    "i128": {
      "kind": "i128",
      "documentation": "A signed 128-bit integer"
    },
    "i16": {
      "kind": "i16",
      "documentation": "A signed 16-bit integer"
    },
    "i32": {
      "kind": "i32",
      "documentation": "A signed 32-bit integer"
    },
    "i64": {
      "kind": "i64",
      "documentation": "A signed 64-bit integer"
    },
    "i8": {
      "kind": "i8",
      "documentation": "A signed 8-bit integer"
    },
    "isize": {
      "kind": "isize",
      "documentation": "A signed pointer-sized integer"
    },
    "u128": {
      "kind": "u128",
      "documentation": "An unsigned 128-bit integer"
    },
    "u16": {
      "kind": "u16",
      "documentation": "An unsigned 16-bit integer"
    },
    "u32": {
      "kind": "u32",
      "documentation": "An unsigned 32-bit integer"
    },
    "u64": {
      "kind": "u64",
      "documentation": "An unsigned 64-bit integer"
    },
    "u8": {
      "kind": "u8",
      "documentation": "An unsigned 8-bit integer"
    },
    "usize": {
      "kind": "usize",
      "documentation": "An unsigned pointer-sized integer"
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant