Godot-proposals: Add ability to load DLL modules without using GDNative

Created on 1 Dec 2020  ·  3Comments  ·  Source: godotengine/godot-proposals

Describe the project you are working on

A game I want to publish on steam

Describe the problem or limitation you are having in your project

We can't integrate the SteamSDK with a little amount of tool setup.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Why:

  • No compiler, only Godot. :cake:
  • Less layers and tools setup
  • Can be used for advertising APIs with less c knowledge, much like p invoke from c#
  • Can be used for proprietary SDK's
  • Distribution is just a zip

Directory structure:

  • docs/

    • Whatever documentation or licensing

  • bin/linux

    • SteamAPI.so

  • bin/windows

    • SteamAPI.dll

  • bin/osx

    • SteamAPI.dylib

  • scripts

    • SteamSDK.gd

Packaging:

Loading modules

  • Must explicitly be enabled in the project.config for security even if you call the module API.

Implement DLL API for standard SDK files like SourceSDK.dll

https://docs.google.com/document/d/1-bxJ0CZb6_Ceuv-SmGCO4YV-lse8NjmRQWvGFlDvL6Y/

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

var module = load_module("SteamAPI")
func authentication_response(user_data : UserStruct, status : String):
    print(“User has authenticated “ + user_data.name)

)
var authenticate = module.bind(“authenticate_steam”, authentication_response)

Please see this document for the below points:
https://docs.google.com/document/d/1-bxJ0CZb6_Ceuv-SmGCO4YV-lse8NjmRQWvGFlDvL6Y

If this enhancement will not be used often, can it be worked around with a few lines of script?

no

Is there a reason why this should be core and not an add-on in the asset library?

it is core

core

Most helpful comment

Another option is using an FFI (this has less performance issues with JIT compilation, should GDScript add it later)
https://luajit.org/ext_ffi.html

They're always faster than using c functions from a jit compiled language. (since standard c calls to c functions are always slower when you have JIT compilation, as it interrupts the jit compilation. which was a constant source of frustration with garrysmod for example because the jit compilation would die every time you called back into the C++ code the FFI prevents this slowdown if memory serves me correctly.

Ideally we start small though, with something very simple and work from there.

All 3 comments

First questions that pops to my mind: how should GDScript handle native types without any translation layer that is created manually when you wrap 3rd party libraries into modules/gdnative classes?

We'd most likely use something like this as a good template for the implementation:

handles all the potential cases for binding c structs correctly, which at first would be good enough to me.

There is the pinvoke method too from csharp but we probably wouldn't use it as a template, the ctypes system is so similar to gdscript it could be used as a template, and we could make further simplifications, if we don't need all the bells and whistles it has.

Another option is using an FFI (this has less performance issues with JIT compilation, should GDScript add it later)
https://luajit.org/ext_ffi.html

They're always faster than using c functions from a jit compiled language. (since standard c calls to c functions are always slower when you have JIT compilation, as it interrupts the jit compilation. which was a constant source of frustration with garrysmod for example because the jit compilation would die every time you called back into the C++ code the FFI prevents this slowdown if memory serves me correctly.

Ideally we start small though, with something very simple and work from there.

Was this page helpful?
0 / 5 - 0 ratings