Commit graph

12 commits

Author SHA1 Message Date
刘皓
b55f6dd1f4
Add more error checking to sandbox bindings
* Added checks for when an incorrect number of arguments is passed to a
  function
* Added checks for when an argument of object type has mismatching type
  (arguments of numeric and string types were already checked for type
  mismatches before this commit)
* Added checks for trying to read certain properties of a disposed
  object
2025-08-18 14:04:09 -04:00
刘皓
c6e33a9ff1
Move sandbox coroutine destructors into an end() method
Follow-up to 9b3240f7b3.

This allows us to choose whether or not to run the destructor when
destroying the coroutines in a way that doesn't cause memory leaks.
2025-07-25 21:21:29 -04:00
刘皓
551206e7b4
Don't set private data if an exception has occurred in the bindings 2025-05-20 18:58:44 -04:00
刘皓
031245491f
Keep track of all C++ objects allocated by bindings in libretro builds
This commit adds `sb()->create_object()`, `sb()->get_object()`,
`sb()->check_object_type()` and `sb()->destroy_object()` in libretro
builds to keep track of all C++ objects allocated by the bindings in
libretro builds. This has some benefits:

* Any C++ objects allocated by the bindings that are still alive when
  the game terminates can now be deallocated instead of being leaked
  like before.
* We now keep track of the types of all objects allocated by the
  bindings, so we will be able to detect when the bindings attempt to
  access objects of mismatching type.
* Keeping track of all allocated objects is required to implement
  libretro save states.
* Objects are now kept track of using numeric keys whose sizes are the
  same on every platform rather than pointers, which helps with making
  save states portable across platforms.
2025-05-19 14:44:44 -04:00
刘皓
83a6b7a1f1
Re-add missing GFX_LOCK/GFX_UNLOCK calls in binding-sandbox 2025-05-17 19:41:43 -04:00
刘皓
134e08ce6a
Allow the entire codebase to build with -fno-exceptions -fno-rtti in libretro builds 2025-05-16 21:59:54 -04:00
刘皓
3ba12e5672
Fix handling of big-endian platforms in libretro builds
In big-endian libretro builds, the WebAssembly memory is reversed, so no
byte-swapping is required to read from/write to WebAssembly memory
(which is little-endian).

However, that means the ways to get and set values in WebAssembly memory
are endianness-dependent, so I've added the correct such ways for
big-endian platforms.
2025-05-10 18:55:14 -04:00
刘皓
b8d785b7e1
Implement growing VM memory in libretro builds
The binding coroutines in libretro builds are constructed on the VM
stack, so reallocating the VM memory would corrupt the memory of any
currently existing coroutines.

I've changed it so that the coroutines are no longer constructed on the
VM stack so that they're unaffected by VM memory reallocations, and
added a "slot" mechanism for storing variables on the VM stack. (Any
Ruby `VALUE`s used by a coroutine have to be stored on the VM stack so
that the Ruby garbage collector doesn't free them while they're being
used, which is why the slot mechanism is necessary.)
2025-05-09 22:49:13 -04:00
刘皓
df559241a2
Complete almost all of the bindings in libretro builds
The only things left are the bindings for the input extensions and
possibly adding in `SANDBOX_YIELD` to the `Graphics.play_movie` binding
later.
2025-05-01 14:32:59 -04:00
刘皓
82b2ad0ef1
Add serializable-binding.h in libretro builds 2025-05-01 13:58:54 -04:00
刘皓
bdcbfd26f1
Add more helper functions for bindings in libretro builds 2025-05-01 11:18:02 -04:00
刘皓
5b94ce4e80
Refactor binding-sandbox header files into .cpp files 2025-04-30 22:31:13 -04:00