Created
January 15, 2024 12:09
-
-
Save pthom/a16b6062e0184cfe6e278d71ae7047ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Namespace MyLibrary: an example namespace that will be exported to python as a module | |
namespace MyLibrary | |
{ | |
// Types of full screen modes (enum class) | |
enum class FullScreenMode | |
{ | |
NoFullScreen, | |
FullScreen, // Full screen with specified resolution | |
FullScreenDesktopResolution, // Full screen with current desktop mode & resolution | |
FullMonitorWorkArea // Fake full screen, maximized window on the selected monitor | |
}; | |
// Types of window modes (enum) | |
enum WindowMode | |
{ | |
WindowMode_Windowed = 1, // Standard window mode | |
WindowMode_Borderless = 1 << 4, // Borderless window mode | |
}; | |
} | |
// SwitchBool: Toggles a boolean flag | |
// - litgen adds a wrapper automatically (immutable types will be boxed in python) | |
// - With robotpy-build, you need to add it manually: | |
// demo.yml | |
// functions: | |
// SwitchBool: | |
// cpp_code: | | |
// // python API | |
// [](bool v) -> bool { | |
// SwitchBool(&v); | |
// return v; | |
// } | |
inline void SwitchBool(bool* inOutFlag) { *inOutFlag = !*inOutFlag;} | |
/// C-style arrays | |
inline int Sum4(int values[4]) { return values[0] + values[1] + values[2] + values[3]; } | |
// A class with a C-style array member | |
struct Foo | |
{ | |
int values[4]; | |
}; | |
//// Some macros values | |
#define MY_MACRO_1 1 | |
#define MY_MACRO_2 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################### <generated_from:BoxedTypes> #################### | |
class BoxedBool: | |
value: bool | |
def __init__(self, v: bool = False) -> None: | |
pass | |
def __repr__(self) -> str: | |
pass | |
class BoxedInt: | |
value: int | |
def __init__(self, v: int = 0) -> None: | |
pass | |
def __repr__(self) -> str: | |
pass | |
#################### </generated_from:BoxedTypes> #################### | |
def add2(x: int) -> int: | |
"""* Adds 2 to the first parameter and returns it""" | |
pass | |
class DemoClass: | |
"""* | |
Doxygen documentation is automatically added to your python objects | |
when the bindings are autogenerated. | |
""" | |
def set_x(self, x: int) -> None: | |
"""* Sets X""" | |
pass | |
def get_x(self) -> int: | |
"""* Gets X""" | |
pass | |
def __init__(self) -> None: | |
"""Autogenerated default constructor""" | |
pass | |
def switch_bool(in_out_flag: BoxedBool) -> MY_API None: | |
""" SwitchBool: Toggles a boolean flag | |
- litgen adds a wrapper automatically (immutable types will be boxed in python) | |
- With robotpy-build, you need to add it manually: | |
demo.yml | |
functions: | |
SwitchBool: | |
cpp_code: | | |
// python API | |
[](bool v) -> bool { | |
SwitchBool(&v); | |
return v; | |
} | |
""" | |
pass | |
def sum4( | |
values_0: BoxedInt, | |
values_1: BoxedInt, | |
values_2: BoxedInt, | |
values_3: BoxedInt | |
) -> MY_API int: | |
"""/ C-style arrays""" | |
pass | |
class Foo: | |
""" A class with a C-style array member""" | |
values: np.ndarray # ndarray[type=int, size=4] | |
def __init__(self) -> None: | |
"""Auto-generated default constructor""" | |
pass | |
#// Some macros values | |
MY_MACRO_1 = 1 | |
MY_MACRO_2 = 2 | |
# <submodule my_library> | |
class my_library: # Proxy class that introduces typings for the *submodule* my_library | |
pass # (This corresponds to a C++ namespace. All method are static!) | |
""" Namespace MyLibrary: an example namespace that will be exported to python as a module""" | |
class FullScreenMode(enum.Enum): | |
""" Types of full screen modes (enum class)""" | |
no_full_screen = enum.auto() # (= 0) | |
full_screen = enum.auto() # (= 1) # Full screen with specified resolution | |
full_screen_desktop_resolution = enum.auto() # (= 2) # Full screen with current desktop mode & resolution | |
full_monitor_work_area = enum.auto() # (= 3) # Fake full screen, maximized window on the selected monitor | |
class WindowMode(enum.Enum): | |
""" Types of window modes (enum)""" | |
windowed = enum.auto() # (= 1) # Standard window mode | |
borderless = enum.auto() # (= 1 << 4) # Borderless window mode | |
# </submodule my_library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
import pybind11_stubgen.typing_ext | |
import typing | |
__all__ = ['DemoClass', 'Foo', 'FullScreenMode', 'WindowMode', 'add2', 'sum4', 'switchBool'] | |
class DemoClass: | |
""" | |
Doxygen documentation is automatically added to your python objects | |
when the bindings are autogenerated. | |
""" | |
def __init__(self) -> None: | |
... | |
def getX(self) -> int: | |
""" | |
Gets X | |
""" | |
def setX(self, x: int) -> None: | |
""" | |
Sets X | |
""" | |
class Foo: | |
def __init__(self) -> None: | |
... | |
@property | |
def values(self) -> memoryview: | |
... | |
class FullScreenMode: | |
""" | |
Members: | |
NoFullScreen | |
FullScreen | |
FullScreenDesktopResolution | |
FullMonitorWorkArea | |
""" | |
FullMonitorWorkArea: typing.ClassVar[FullScreenMode] # value = <FullScreenMode.FullMonitorWorkArea: 3> | |
FullScreen: typing.ClassVar[FullScreenMode] # value = <FullScreenMode.FullScreen: 1> | |
FullScreenDesktopResolution: typing.ClassVar[FullScreenMode] # value = <FullScreenMode.FullScreenDesktopResolution: 2> | |
NoFullScreen: typing.ClassVar[FullScreenMode] # value = <FullScreenMode.NoFullScreen: 0> | |
__members__: typing.ClassVar[dict[str, FullScreenMode]] # value = {'NoFullScreen': <FullScreenMode.NoFullScreen: 0>, 'FullScreen': <FullScreenMode.FullScreen: 1>, 'FullScreenDesktopResolution': <FullScreenMode.FullScreenDesktopResolution: 2>, 'FullMonitorWorkArea': <FullScreenMode.FullMonitorWorkArea: 3>} | |
def __eq__(self, other: typing.Any) -> bool: | |
... | |
def __getstate__(self) -> int: | |
... | |
def __hash__(self) -> int: | |
... | |
def __index__(self) -> int: | |
... | |
def __init__(self, value: int) -> None: | |
... | |
def __int__(self) -> int: | |
... | |
def __ne__(self, other: typing.Any) -> bool: | |
... | |
def __repr__(self) -> str: | |
... | |
def __setstate__(self, state: int) -> None: | |
... | |
def __str__(self) -> str: | |
... | |
@property | |
def name(self) -> str: | |
... | |
@property | |
def value(self) -> int: | |
... | |
class WindowMode: | |
""" | |
Members: | |
Windowed | |
Borderless | |
""" | |
Borderless: typing.ClassVar[WindowMode] # value = <WindowMode.Borderless: 16> | |
Windowed: typing.ClassVar[WindowMode] # value = <WindowMode.Windowed: 1> | |
__members__: typing.ClassVar[dict[str, WindowMode]] # value = {'Windowed': <WindowMode.Windowed: 1>, 'Borderless': <WindowMode.Borderless: 16>} | |
def __eq__(self, other: typing.Any) -> bool: | |
... | |
def __getstate__(self) -> int: | |
... | |
def __hash__(self) -> int: | |
... | |
def __index__(self) -> int: | |
... | |
def __init__(self, value: int) -> None: | |
... | |
def __int__(self) -> int: | |
... | |
def __ne__(self, other: typing.Any) -> bool: | |
... | |
def __repr__(self) -> str: | |
... | |
def __setstate__(self, state: int) -> None: | |
... | |
def __str__(self) -> str: | |
... | |
@property | |
def name(self) -> str: | |
... | |
@property | |
def value(self) -> int: | |
... | |
def add2(x: int) -> int: | |
""" | |
Adds 2 to the first parameter and returns it | |
""" | |
def sum4() -> tuple[int, typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(4)]]: | |
""" | |
C-style arrays | |
""" | |
def switchBool(inOutFlag: bool) -> bool: | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment