World: r3wp
[!REBOL3 Extensions] REBOL 3 Extensions discussions
older newer | first last |
BrianH 6-Nov-2009 [335x4] | A command! is an indexed dispatch function, and the index has no inherent meaning. You could dynamically generate functions with libtcc, which would all have the same function signiature because they would just take command! call frames. These generated functions could be referenced from an array of function pointers. After you generate a new function and assign it to a new array slot, return the index of that slot to the calling REBOL code (embedded in the libtcc extension) and it can then make a command! with the libtcc extension's handle and that index. Then that command! can be called like any other REBOL function. A trick though is that the generated C code would need to use the extension macros to manipulate the function arguments, rather than direct variable access. In other words, your generated functions would be extension-style code, not regular C code. |
Pekr, the reason callbacks are so tricky in R3 is that you need a way to dispatch to the correct task within REBOL. R3 is not going to be single-tasking anymore, so direct callbacks will be impossible: You have to coordinate between the task/thread of the external code and the tasks/threads of R3. Devices manage that coordination and synchronization. | |
Bolek, if you have the commands that are exported from the libtcc extension themselves implemented as functions with the same signiature as the generated functions, you can call them through the dispatch array as well. This would reduce your RX_Call function to just a few lines. | |
Be sure to BSD the extension wraapper code though, so it can be reused by an LLVM wrapper :) | |
Rebolek 6-Nov-2009 [339x2] | If you mean BSD-license, that's understood. I prefer PD/MIT/BSD licenses, GPL is stupid. |
(I prefer no licenses at all, but I'm an anarchist) | |
BrianH 6-Nov-2009 [341x3] | Well, libtcc is LGPL (2, I think), as is libjit, but LLVM is BSD. The extension interface is LGPL compatible, so if you BSD the wrapper code (or more permissive, as long as it's LGPL compatible) then you should be fine. |
I prefer more permissive licenses too :) | |
especially PD | |
Rebolek 6-Nov-2009 [344] | I'm fine with PD - code is just organized characters. Milion monkeys with typewriters can do same thing ;) so why licensing anything. But that's offtopic - the license will not be deffinitely more restrictive than BSD and it may be PD as well. Depends on my mood when I add it to header ;) |
BrianH 6-Nov-2009 [345] | libtcc is LGPL 2.1 |
Robert 28-Nov-2009 [346x5] | Playing with the extension example: IMO it's done to complicated. - Why do I need make-ext.r? Do I always need it or just for this specific example? - Why is the init block a const char array and not just a plain ASCII text? |
How do I return a new string back to Rebol? | |
I seems I need to construct a RX string and set every single char? | |
This uniton gives a warning/error with mingw: typedef union rxi_arg_val { i64 int64; double dec64; REBYTE bytes[8]; struct { i32 int32a; i32 int32b; }; struct { u32 index; void *series; }; void *handle; } RXIARG; | |
The structs give: warning: declaration does not declare anything | |
Ladislav 28-Nov-2009 [351x3] | yes, Robert, the other elements clearly declare something, but the structs don't declare anything, the compiler is right |
generally, struct {...} my-struct; declares my-struct, while struct {...}; does not declare anything | |
(should have been my_struct) | |
Robert 28-Nov-2009 [354] | I commented the struct part and than it works. So either we need to give it a name, which will result in a ->struct_name.series sequence. Not sure if this makes any difference instead of just putting the members into the union. |
Ladislav 28-Nov-2009 [355x3] | yes, it makes a difference |
(since it is a union) | |
-only one of the variants is correct | |
Robert 28-Nov-2009 [358x4] | Ok, right. Using int32 and ser as struct names. |
Works. | |
BTW: I'm currently making a R3 SQLite extension. | |
Looks like one need to be carful when designing the command interface (arguments) because if you insert an argument, the refinements shift to a new position. As the access to arguments on the c side is via positions you need to adjust your code. Need to think abou a good way to abstract this. | |
jocko 29-Nov-2009 [362] | is there a document showing how to define refinements in extensions ? |
Robert 29-Nov-2009 [363x2] | What do you mean with "define"? On the Rebol side or on the C side? |
Anyhow, yes refinements are no problem. | |
jocko 29-Nov-2009 [365] | well in fact I have not found any mechanism to call a function with a changing number of arguments, like, for instance: my-func a b my-func a b c or, my-func a b my-func/my-refinement a b c |
Graham 29-Nov-2009 [366] | use a block of arguments ? |
jocko 29-Nov-2009 [367x2] | Yes, of course it is a solution, but not a clean on in my case in fact, you cannot know, from inside the C part of the code, the real number of arguments send to the function. |
RXA_COUNT returns the number of arguments defined by the prototype of the function, not the actual one | |
Gabriele 29-Nov-2009 [369] | Jocko... you know... it has never been possible in REBOL to define functions with a variable number of arguments... |
Rebolek 29-Nov-2009 [370] | it is possible, but usefull only in console |
jocko 29-Nov-2009 [371] | that is why I was thinking of refinements |
BrianH 29-Nov-2009 [372] | The method of calling with refinements is currently awkward. That is one of the problems that is intended to be addressed in the near future in further revisions of the extensions api. |
jocko 29-Nov-2009 [373] | thanks, ... I hope that another (awkward) item will be callbacks. |
Robert 29-Nov-2009 [374] | It works but it's only done via position, so you don't get the name of the refinement. This rule is an unnecessary dependency from Rebol code to C code. |
jocko 29-Nov-2009 [375] | Ok, I understand ... |
BrianH 29-Nov-2009 [376] | Same as APPLY, actually. Fortunately the C implementation and the REBOL declaration are bundled together, so you tend to be the one setting the positions in the first place. This makes the whole process easier. |
jocko 29-Nov-2009 [377] | Ok, I see |
BrianH 29-Nov-2009 [378x2] | However, don't expect such awkwardness to continue for much longer. This is just version 11 :) |
11 -> 1 (stupid keyboard) | |
Robert 29-Nov-2009 [380x2] | May be, but that's what's available at the moment. |
Is there anyway to do a callback? Or trigger R3 to do something? At the moment I use a localhost port for this. | |
BrianH 29-Nov-2009 [382x2] | Not at the moment. That is as good a method as any for now. Maxim has beeen doing some research on this, and the device model is supposed to solve this problem in the long run. |
Some parts of R3 are more alpha than others - the extension model is one of these. | |
Robert 29-Nov-2009 [384] | That's bad because it's IMO an enabler and promoter for R3. As long as the GUI is missing, at least R3 can be used on the server with extensions. |
older newer | first last |