Giter Club home page Giter Club logo

Comments (15)

ghyatzo avatar ghyatzo commented on July 24, 2024 1

duh... sorry its morning here. I see, does @ccall supports varargs while ccall doesnt?
ok now it's like this

 @ccall libcimgui.igText("Hello %s %s"::Cstring; "world"::Cstring, "!"::Cstring)::Cvoid    # Hello world !
 ccall((:igText, libcimgui), Cvoid, (Cstring, Cstring, Cstring), "Hello %s %s", "world", "!") # Hello world !
 ccall((:igText, libcimgui), Cvoid, (Cstring, Cstring), "test pre %s", "test") # test pre world
 ccall((:igText, libcimgui), Cvoid, (Cstring, Cstring), "%s", "hello") # world

from cimgui.jl.

ghyatzo avatar ghyatzo commented on July 24, 2024 1

Got it working with, otherwise it would print fmt as well.

@ccall libcimgui.ImPlot_Annotate_Str(1::Cdouble, 2::Cdouble, ImVec2(0, 0)::ImVec2, "%s %s"::Cstring; "a"::Cstring, "b"::Cstring)::Cvoid

Shall I make an issue to implot? or is that a generator issue?

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

Does the following vararg version of the text API work on aarch macOS?

@ccall libcimgui.igText("Hello %s %s"::CString; "world"::CString, "!"::CString)::Cvoid

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

BTW, CString is not mandatory. You can use Ptr{Cuchar} instead.

from cimgui.jl.

ghyatzo avatar ghyatzo commented on July 24, 2024

I have tried a couple of variations, in steps towards the normal CImGui.Text(text).

here's what happens

 @ccall libcimgui.igText("Hello %s %s"::Cstring, "world"::Cstring, "!"::Cstring)::Cvoid    # Hello jl_fptr_args ??N?
 ccall((:igText, libcimgui), Cvoid, (Cstring, Cstring, Cstring), "Hello %s %s", "world", "!") # Hello jl_fptr_args ??N?
 ccall((:igText, libcimgui), Cvoid, (Cstring, Cstring), "test pre %s", "test") # test pre jl_fptr_args
 ccall((:igText, libcimgui), Cvoid, (Cstring, Cstring), "%s", "hello") # segfaults

the ??N? would change to other random stuff (sometimes also the jl_fptr_args part) every time I started a new julia sessions. (different location in memory?)

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

The first , in the ccall macro version should be ;

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#Mapping-C-Functions-to-Julia

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

ccall only support a limited version of varadic arguments where each vararg should be of the same type.

from cimgui.jl.

ghyatzo avatar ghyatzo commented on July 24, 2024

I noticed there is also a (probably) related issue with ImPlot annotations, as they only show as ??.
I am toying around by redefining the implot calls using @ccall, there is a problem. I don't understand how to unpack tuples into varargs
for example

function Annotate(x::Real, y::Real, pix_offset::ImVec2, fmt::String...)
    @ccall libcimgui.ImPlot_Annotate_Str(x::Cdouble, y::Cdouble, pix_offset::ImVec2; fmt::Cstring)::Cvoid
end

complains, and

@ccall libcimgui.ImPlot_Annotate_Str(x::Cdouble, y::Cdouble, pix_offset::ImVec2; fmt::Cstring...)::Cvoid

complains as well.

Do you know if it is possible to splat into the call? I guess I could splat before the macro expansion with an eval, but eww...

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

Clang.jl has a prototype for wrapping vararg functions: https://github.com/JuliaInterop/Clang.jl/blob/9a519baa45000d2afe1262ae7463cc0795671721/gen/generator.toml#L163

But I never use that. Isn't the @ccall macro already concise to write?

from cimgui.jl.

ghyatzo avatar ghyatzo commented on July 24, 2024

I meant that if I were to call
Annotate(1, 2, ImVec2(0, 0), "a", "b", "c") in the first example typeof(fmt) == Tuple{String} and it complains it can't convert it into a Cstring, while in the second example it does not recognise ::Cstring... as a valid argument type and complains that fmt does not have one.

fmt...::Cstring... does not work as well.
found this as well: https://discourse.julialang.org/t/why-is-ccall-syntax/72427/6

Anyhow, I tested with

function Annotate(x::Real, y::Real, pix_offset::ImVec2, fmt::String)
    @ccall libcimgui.ImPlot_Annotate_Str(x::Cdouble, y::Cdouble, pix_offset::ImVec2; fmt::Cstring)::Cvoid
end

so accepting only one string, but it still shows ?? in annotations

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

Does it work if you directly use @ccall libcimgui.ImPlot_Annotate_Str(1::Cdouble, 2::Cdouble, ImVec2(0, 0)::ImVec2; "a"::Cstring, "b"::Cstring, "c"::Cstring)::Cvoid?

from cimgui.jl.

ghyatzo avatar ghyatzo commented on July 24, 2024

Nope, still ??

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

According to https://github.com/cimgui/cimplot/blob/d68fa3abd4fe75312089e9332917a6c326704a58/cimplot.h#L965, the correct way to invoke the API is @ccall libcimgui.ImPlot_Annotate_Str(1::Cdouble, 2::Cdouble, ImVec2(0, 0)::ImVec2, "fmt %s %s"::Cstring; "a"::Cstring, "b"::Cstring)::Cvoid

EDIT: updated the wrong ; position

from cimgui.jl.

IanButterworth avatar IanButterworth commented on July 24, 2024

This is a blocker for me on Apple Silicon. Has there been any progress?

Also, I note that CImGui.Text(text) = CImGui.TextUnformatted(text) does work for me as a workaround

from cimgui.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.