scala-interop/slinc

How to deal with "String"?

Quafadas opened this issue · 4 comments

From reading the unit tests, I had believed the strategy should have looked something like this;

https://github.com/Quafadas/slincTest/blob/890eee0abbc30f507a629b5b8bc043915c51ec9c/slinc.scala#L30

Pseudo code

import fr.hammons.slinc.types.*

@NeedsFile("""C:\temp\superJlibCompiled\bin\libjulia.dll""")
trait SuperJLib derives FSet:
  def jl_eval_string(code : Ptr[CChar]):Unit
...

val jLib = FSet.instance[SuperJLib]

...
 val t = Ptr.copy("print(sqrt(2.0))")
jLib.jl_eval_string( t );

However, I get a compilation error;

[error] .\slinc.scala:30:39: No given instance of type fr.hammons.slinc.Allocator was found for parameter x$2 of method copy in object Ptr

I can't see where my imports are different to the unit tests... stuck? Any hints / something obviously wrong with how I'm attempting this?

Have you imported the runtime? import fr.hammons.slinc.runtime.given

I'm sorry the API isn't super well documented or organized right now. I have plans to reorder things to be easier to deal with, but there are higher priority tickets still. 😣

Ah sorry, this is a different issue. For creating Ptr types, you need a scope:

Scope.confined{
  Ptr.copy("my string")
}

Scopes generally control allocation and deallocation of native memory.

Yeah - thanks worked!

Maybe I submit a tiny doc PR for you...