World: r3wp
[Red] Red language group
older newer | first last |
Pekr 11-Feb-2012 [4827x4] | Maybe one another question - I know Red/System is supposed to be closer to C, but it will be also used by those, who would like to proceed using Red itself (that is why I did not like the print-line, ?? vs print/prin) - so the question - why is there so many constructors, instead of one make! and e.g. a block format? I mean: declare struct! alias struct! #import for a library Intead of: make struct! make lit-struct! make routine! ? I will understand the answer of a type, that it is better to be understood by those knowing C language. So far, I can't e.g. understand, why a library is wrapped in a preprocessor kind of way, using #import, which does not fit those preprocessor things like #define, #ifdef, etc.? |
Btw - once you add TYPE? function,I wonder how you distinguish declared struct! from an aliase one :-) I know that function will return integer, but you will surely print some name in the end, so will you come with an artificial type-name for an aliased struct to distinguish? | |
If it would be upon me, I would better try to stay consistent with the Red level - so if Red will have make!, Red/System should have make too, no matter how C users will aproach it. Those who will use Red/System, are going to use Red most probably too, so I can not see much reasons to differ, just because we can state - Red and Red/System are two different things :-) I am curious how you will keep up with such a differences in future, once Red layer becomes available :-) | |
c: 2 p/c: 1234 ;-- writes 123 (4 bytes) at 40000004h Isn't there a typo? Shouldn't it be - "writes 1234 (4 bytes) at 40000004h"? | |
Kaj 11-Feb-2012 [4831] | Looks like it was written with a sleep deficit :-) |
Pekr 11-Feb-2012 [4832] | just a small typo, so other than that, docs are good :-) |
Kaj 11-Feb-2012 [4833x2] | Literals are a quite generic concept from REBOL. An ALIAS is a much more specific thing: it's a name for a struct!. If you want to compare it to REBOL, you could say that it's bound to the struct, so not just a literal |
I wonder if TYPE would be a better name for it | |
Pekr 11-Feb-2012 [4835] | so that is has already a type, and the type is struct, whereas literal is just a literal? |
Kaj 11-Feb-2012 [4836] | There are no literals in Red/System, at least not as symbols |
Pekr 11-Feb-2012 [4837x3] | because "alias", although I am not a native english speaking person, in my understanding, is something already existing, which we reference. But a struct alias is just like a class, it is not structure yet. But, it does not probably matter. Simply put coming from REBOL I would like to see those two similar. Reading further in docs I can see, that REBOL can't be easily mapped to C, so some specialisties might be needed ... |
It is more of a philosophy, what is more confusing to whom. E.g. Carl proposes dialecting as the same word, being simply used in different context. In real life, it might work, but not sure about programming. E.g. 'copy in 'parse having slightly different aspects than 'copy in REBOL itself. That is why I thought that make! could be used even in Red/System, but not sure ... | |
The reason why I am also opting for such an aproach is, that there will be possibility to inline Red/System in Red itself, so it should look similar, where possible. I e.g. liked how Cyphre did JIT to R2 - the code still looks like REBOL, it is just a limited subset ... | |
Kaj 11-Feb-2012 [4840x3] | I share some of your uneasy feelings about the overuse of preprocessing constructs. I would like them to become first-class, but it's hard to come up with the best solutions |
I think Doc will say that we'll reconsider them in the Red/System rewrite in Red | |
Your binding looks quite good to me, but how is your #import defined, and how is WINAPI defined in the C code? | |
Pekr 11-Feb-2012 [4843] | Yes, that might actually happen, after all Red/System is the target, so new needs might show-up during the Red design, who knows .... |
Kaj 11-Feb-2012 [4844] | They will, and they have |
Pekr 11-Feb-2012 [4845] | I tried stdcall and iirc even cdecl. How do I find out? |
Kaj 11-Feb-2012 [4846x2] | It should probably be cdecl, and the WINAPI definition probably contains the answer. Did it make a difference? |
The issue looks to be that the C functions are defined as WINAPI pointers, instead of just WINAPI functions | |
Pekr 11-Feb-2012 [4848] | No, still error ... |
Kaj 11-Feb-2012 [4849] | Is LSN_GETBRIGHT really defined as LSN_GetBright, etc, or are the function names different? |
Pekr 11-Feb-2012 [4850x2] | maybe not, I found this: extern LSN_GETBRIGHT fpGetBright ; |
Does it mean, that the real func name is fpGetBright? | |
Kaj 11-Feb-2012 [4852] | I think so, but the C code is also doing an indirection through a function pointer, hence the fp |
Pekr 11-Feb-2012 [4853x2] | But some functions work although defined the same way. There might be some more functionality happenening under the hood, and who knows, that the code tries to return. OTOH the specs are clear enough - if it is supposed to return integer, then integer is simply an integer. And dialog windows work - I e.g. got dialoc saying "LED screen not found", so the GUI is inside the dlls ... |
Never mind, I just wanted to try it in Red. Good way to become familiar with the system trying to use it for practical purpose. I might try to continue investigatin COM communication, but R2 serial communication is also not much to be desired :-) | |
Kaj 11-Feb-2012 [4855] | Are all C functions defined as pointers (with * and fp markers)? Can you give an example of a binding that works? |
Andreas 11-Feb-2012 [4856] | typedef int (WINAPI *LSN_GETBRIGHT)() ^^ That defines LSN_GETBRIGHT to be another name for a pointer to a stdcall function that takes no arguments and returns an int. (WINAPI == __stdcall) extern LSN_GETBRIGHT fpGetBright ; ^^ That now is the actual "function", although held indirectly as a function pointer. So somewhere in a library is a fpGetBright value which holds a LSN_GETBRIGHT function pointer. In C you can directly call that as e.g. `int brightness = fpGetBright();`. However, I fear in Red/System it's at the moment not possible to perform that call. |
Pekr 11-Feb-2012 [4857x2] | sorry, sitting in the bar, running via team viewer on my htc sensation, so limited pc usability right now :-) |
Andreas - interesting. How is that some functions being defined the same way work? | |
Andreas 11-Feb-2012 [4859] | No idea, which one works :) ? |
Pekr 11-Feb-2012 [4860x2] | typedef bool (WINAPI *LSN_ISPOWER)(void); //??????,???0?1? typedef bool (WINAPI *LSN_POWER)(bool); //??????,??0??,1?? typedef bool (WINAPI *LSN_ISLOCK)(void); //????,???0?1? typedef bool (WINAPI *LSN_LOCK)(bool); //????,??0?1? |
uff, team viewer had someproblem switching focus, or it was me :-) so, turning on and off the screen works ... not just a - led screen reacts ... | |
Andreas 11-Feb-2012 [4862x2] | Well, maybe there actually is a LSN_Power function in the DLL you are linking to :) |
I'd directly look at the DLL's exports first, to see what's actually going on there. After that you can go looking for the corresponding definitions in C headers or docs. | |
Pekr 11-Feb-2012 [4864] | actually i have a whole app source fes, at least i think. but there is not much to look into, that is just an utility to parametrose led screen. I dont want to bother anyone with it, I thought you might see some obvious error i am doing, but apparently the issue is more complex ... |
Kaj 12-Feb-2012 [4865x3] | The obvious error is that the C function names you're using are incorrect. As Andreas said, you probably happened to hit some functions by that name for the ones that do something |
The complex issue is that the functions are imported through pointers. Red/System can use function pointers if you write wrapper functions and pass them the function pointers. But Red/System can't import simple values yet, only functions, so you can't import the function pointers the way the C code does | |
However, the functions may also be exported the normal way, in which case you wouldn't have to use the pointers, but you would have to find the names of the real functions. For fpGetBright I would look for GetBright for example | |
Pekr 12-Feb-2012 [4868x2] | Here's how they are defined: fpIsPower = (LSN_ISPOWER)GetProcAddress(g_hLedCtrlInst, "LSN_IsPower"); fpPower = (LSN_POWER)GetProcAddress(g_hLedCtrlInst, "LSN_Power"); fpIsLock = (LSN_ISLOCK)GetProcAddress(g_hLedCtrlInst, "LSN_IsLock"); fpLock = (LSN_LOCK)GetProcAddress(g_hLedCtrlInst, "LSN_Lock"); fpGetBright = (LSN_GETBRIGHT)GetProcAddress(g_hLedCtrlInst, "LSN_GetBright"); First three work, fpGetBright, which is wrapped as LSN_GetBright (as this is actual name in exports of DLL), does not work. They all look to me being defined the same way, no? How is that first three work? |
btw - does that mean, that Red/System is still not generally good enough, to wrrap "any" C interfacing? | |
PeterWood 12-Feb-2012 [4870] | I guess you're correct; Red/System is not generally good enough to wrap "any and all" C libraries yet. What is most important to me about Red/System at this time is that it needs to be good enough to allow Red to be developed. I believe the addition of partial float support to Red/System was not absolutely essential for the development of Red though I'm sure it will help. There are lots of other improvements that could and will eventually be made to Red/System but they don't seem as important as work on Red ... at least to me. |
Robert 12-Feb-2012 [4871] | Doc, take a look at how Lua does the C interface. It's really great. Both ways, simple and works. |
Pekr 12-Feb-2012 [4872x2] | btw - is/will something like inlined/included C/ASM code be possible in Red/System? |
Robert - is it about the interface of LUA done right, or about LUA being somehow close to C? | |
Geomol 12-Feb-2012 [4874x2] | The interface is done right. |
Lua is a scripting language, probably closer to languages like Python (and REBOL), than to C. | |
Andreas 12-Feb-2012 [4876] | Lua's C interface design is not applicable to Red/System; it can provide inspiration for Red, but I think the plan is to interface with C/C-level code from Red via Red/System. |
older newer | first last |