jacksondunstan / UnityNativeScripting

Unity Scripting in C++
https://jacksondunstan.com/articles/3938
MIT License
1.34k stars 135 forks source link

How to automatic convert C++ types to Managed types? #34

Closed sekkit closed 5 years ago

sekkit commented 5 years ago

Successfully embedded Python to UnityNativeScripting, but when executing code below: import UnityEngine UnityEngine.Debug.Log('hello')

TypeError: Log(): incompatible function arguments. The following argument types are supported:

  1. (self: System::Object) -> None

Invoked with: 'helloworld'

At:

(3): UnityEngine.Debug:Log(Object) NativeScript.Bindings:UnityEngineDebugMethodLogSystemObject(Int32) (at Assets/NativeScript/Bindings.cs:1372)
sekkit commented 5 years ago

PS: I wanna do: UnityEngine::Debug::Log("helloworld") instead of System::String msg = System::String("hellworld"); UnityEngine::Debug::Log(msg)

All basic types shall be automatically casted to Managed types.

jacksondunstan commented 5 years ago

I can't speak for the Python part, but I can talk about the C++ side. Passing C++ string literals to functions that take an Object isn't currently possible because a string literal is const and, since C# functions have no concept of const, the parameter is not const in C++. So the compiler rightly complains that a const value is being passed as a non-const parameter.