{"id":15092938,"url":"https://github.com/smack0007/sdl_ts","last_synced_at":"2025-04-12T06:20:46.622Z","repository":{"id":58384522,"uuid":"472492690","full_name":"smack0007/SDL_ts","owner":"smack0007","description":"SDL bindings for TypeScript.  Currently running on deno.","archived":false,"fork":false,"pushed_at":"2025-01-11T13:25:52.000Z","size":8424,"stargazers_count":32,"open_issues_count":3,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-26T01:41:27.011Z","etag":null,"topics":["deno","deno-module","ffi","ffi-bindings","sdl2","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smack0007.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-21T19:59:20.000Z","updated_at":"2025-02-02T09:20:37.000Z","dependencies_parsed_at":"2024-06-07T06:47:17.964Z","dependency_job_id":"a9b62b27-c9e7-499a-b5b9-ca58c0caf0d8","html_url":"https://github.com/smack0007/SDL_ts","commit_stats":{"total_commits":268,"total_committers":6,"mean_commits":"44.666666666666664","dds":0.04477611940298509,"last_synced_commit":"adb4c66d2d224476bf91879237615f7723994801"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smack0007%2FSDL_ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smack0007%2FSDL_ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smack0007%2FSDL_ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smack0007%2FSDL_ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smack0007","download_url":"https://codeload.github.com/smack0007/SDL_ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525756,"owners_count":21118747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","deno-module","ffi","ffi-bindings","sdl2","typescript"],"created_at":"2024-09-25T11:01:55.011Z","updated_at":"2025-04-12T06:20:46.591Z","avatar_url":"https://github.com/smack0007.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SDL_ts\n\n[SDL](https://www.libsdl.org/) bindings for [TypeScript](https://www.typescriptlang.org/).\n\nCurrently working via [deno](https://deno.land/) on Windows, Linux, and mac OS using\n[FFI](https://deno.land/manual/runtime/ffi_api) (Foreign Function Interface).\n\n## Primary Goals\n\n- Resembling the C API as much as possible. If someone reads a SDL tutorial (for example\n  [LazyFoo](https://lazyfoo.net/tutorials/SDL/)) then they should be able to easily translate the tutorial to the\n  equivalent in this library.\n\n## Secondary Goals\n\n- Provide utiltiy functions which wrap SDL features into idomatic JavaScript (i.e. `Events.asyncIterator`).\n\n## Non Goals\n\n- Creating a higher level API or Game Framework. This library's only purpose is to expose the SDL API to TypeScript.\n\n## Versioning\n\nThis library's version number will match the SDL major and minor version against which it is currently tested. The patch\nnumber will be specifici to this library. I.E.\n\n## Getting Started\n\n### SDL2 Installation\n\n#### Linux\n\n##### Debain\n\n```shell\nsudo apt install libsdl2-2.0-0 libsdl2-image-2.0-0 libsdl2-ttf-2.0-0\n```\n\n##### Fedora\n\n```shell\nsudo dnf install SDL2 SDL2_image SDL2_ttf\n```\n\n#### Windows\n\n##### MSYS2\n\n```shell\npacman -S mingw-w64-ucrt-x86_64-SDL2 mingw-w64-ucrt-x86_64-SDL2_image mingw-w64-ucrt-x86_64-SDL2_ttf\n```\n\nYou'll need to ensure then that the sysroot (in this case ucrt) is in your path. Assuming the default install location\nfor msys2 then `C:\\msys64\\ucrt64\\bin`.\n\n#### MacOS\n\n##### Homebrew\n\n```shell\nbrew install sdl2 sdl2_image sdl2_ttf\n```\n\n### Creating a Project\n\nLocated in the directory [examples/getting-started](examples/getting-started/) are a minimal set of files needed to get\na project up and running. Copy these files onto your computer and start the project with `deno task start`. You should\nsee a window with `SDL_ts` as the title.\n\n### Loading shared libraries\n\nUnless `libraryPath` is specified in the `Init` functions, `SDL_ts` will attempt to \"find\" the SDL shared libraries by\ndetermining the prefix and file extension appropriate for the operating system and looking in a set of different places\nalso based on the operating system. The places where the shared libraries are searched for can be influenced by the\nenvironment variable [`SDL_TS_LIBRARY_PATH`](#sdl-ts-library-path).\n\n#### libraryPath\n\nThe `Init` functions (i.e. `SDL_Init`) have in their `options` object a `libraryPath` property. This property should be\na path to the shared library and `SDL_ts` will make no attempt to guess where the library should be loaded from. This\nmeans it's up to the caller of the `Init` function to account for changes in the name of the library between the\ndifferent platforms. For example the shared library on Linux is called `libSDL2.so` and Windows it is called `SDL2.dll`.\nThere is a `lib` prefix on Linux and on Windows the file extension is `.dll` instead of `.so`.\n\n#### SDL_TS_LIBRARY_PATH\n\nThe environmnet variable `SDL_TS_LIBRARY_PATH` can be used to instruct SDL_ts where the SDL shared libraries should be\nloaded from. See [deno.json](deno.json). All example projects will load the SDL shared libraries from the `.lib`\ndirectory if it exists.\n\n### Loading only required functions\n\nPer default `SDL.Init` (or `IMG.Init` or `TTF.Init`) will load all known functions from the SDL assemblies. This can be\nproblematic when attempting to run your script on an older version of the SDL assemblies than the version against which\nthis library is developed. The Init functions accept an options parameter in which the functions to load can be\nspecified:\n\n```ts\nSDL.Init(SDL.InitFlags.VIDEO, {\n  functions: [\n    SDL.Init,\n    SDL.PollEvent,\n    SDL.Quit,\n    // And so on\n  ],\n});\n```\n\n## Concepts\n\n- `AllocatableStruct`: is a `Struct` that can be allocated from JavaScript and will be backed by a `Uint8Array`. The\n  constructor allows all properties to be set in a few ways.\n\n- `OpaqueStruct`: is a `Struct` where no properties are known to JavaScript (C code would also know about the fields)\n  and can only be created by the native side. The `Struct` can only be passed back to the native side and usally to a\n  function that will return information related to the `Struct`. The best example of this concept is `SDL.Window`.\n\n- `Pointer\u003cT\u003e`: represents a pointer to something and is explicitly typed as `unknown` by SDL_ts. `Pointer\u003cT\u003e` can only\n  be returned from functions and will never be created by the JavaScript side. The concept of pointers can't completely\n  be hidden when interfacing with SDL but SDL_ts attempts to constrain pointers to a type level concept. SDL_ts will\n  take care of passing pointers to the native side as part of the marshalling process. See `PointerLike\u003cT\u003e`.\n\n- `PointerLike\u003cT\u003e`: is used only as an input to functions and is used to represent anything to which a pointer can be\n  created for. This includes `Pointer\u003cT\u003e`, `TypedArray`(s), `Struct`(s) and `StructArray`(s).\n\n- `Struct`: the JavaScript representation of structs from the native side. `Struct`(s) are special classes because their\n  data is either a `Pointer\u003cT\u003e` or a `Uint8Array`. If the `Struct` data is a `Pointer\u003cT\u003e` the `Struct` it was allocated\n  on the native side and is read only (see `OpaqueStruct`). If the `Struct` data is an instance of `Uint8Array` it was\n  allocated on the JavaScript side and can be written to as well as read from (see `AllocatableStruct`).\n\n- `StructArray`: Use the `StructArray` class to allocate an array on `Struct`(s). All `Struct`(s) in the the array will\n  be backed by a shared `Uint8Array` allowing the entire array to be passed to the native side. Normal JavaScript arrays\n  are not guarenteed to be laid out contiguously in memory. The `Struct` type passed to the constructor of the array\n  must be an `AllocatableStruct`. All `Struct`(s) passed into the the constructor will have their data copied into the\n  shared `Uint8Array`.\n\n## Credits\n\nDeno images taken from https://deno.land/artwork.\n\nThanks to:\n\n- [Samip Poudel](https://github.com/SamipPoudel58) for the Jurassic deno image.\n- [Andy Baird](https://github.com/ajbdev) for initial MacOS Support.\n- [Yiheng Wu](https://github.com/jingkaimori) for struct handling and other bug fixes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmack0007%2Fsdl_ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmack0007%2Fsdl_ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmack0007%2Fsdl_ts/lists"}