sonoro1234 / LuaJIT-ImGui

LuaJIT ffi binding for imgui, backends and extension widgets
MIT License
213 stars 29 forks source link

Using InputText with callback throws error #15

Closed tversteeg closed 4 years ago

tversteeg commented 4 years ago

When I use the following code I get too many callbacks as an error after a while:

lib.igInputText("##input", "test", 1024, ig.lib.ImGuiInputTextFlags_CallbackCompletion, function()
    print("Hi")
    return 0
end, nil)

What is the proper way to pass callbacks to InputText?

sonoro1234 commented 4 years ago

First create a callback as

local cbt = ffi.cast("ImGuiInputTextCallback",function(aa)
    print("Hi",aa)
    return 0
end)

and use cbt as callback. If not doing this you create a new callback each time

tversteeg commented 4 years ago

Thanks for the quick reply.

When I do this I get a bad callback error.

If I do print(cbt) I do get:

cdata<int (*)()>: 0x....

Do you know why it doesn't work?

sonoro1234 commented 4 years ago

look for bad callback at http://luajit.org/ext_ffi_semantics.html

may be you need to use jit.off (not in my test)

with your call, also this is generated :

bad argument #2 to 'igInputText' (cannot convert 'string' to 'char *')

tversteeg commented 4 years ago

Turning of JIT with jit.off() seems to work, what I also found out in the meantime is that the following also works:

ffi.cast("int (__stdcall *)(ImGuiInputTextCallbackData*)", ..

with your call, also this is generated :

bad argument #2 to 'igInputText' (cannot convert 'string' to 'char *')

This is true, it was just example code because I wrapped it in my own functions but that's too verbose for this example.

sonoro1234 commented 4 years ago

solved