World: r3wp
[!REBOL3 Extensions] REBOL 3 Extensions discussions
older newer | first last |
ChristianE 30-Nov-2010 [1802] | I never got RL_FIND_WORD to work, but I stopped trying around A102 I guess and forgotten about it since then. |
Oldes 30-Nov-2010 [1803] | (never mind, time to sleep for a while:) |
ChristianE 30-Nov-2010 [1804] | Yeah, time for bed here too, good night. |
Oldes 1-Dec-2010 [1805x5] | hm.. I think I understand how it's supposed to work now, but it looks it's just a temp solution. Here is the init part for graphics: words: [ ;gui-metric screen-size border-size border-fixed title-size work-origin work-size ] ;temp hack - will be removed later init-words: command [ words [block!] ] init-words words |
But I think that the easiest way is to define the enum constants during the extension init like: export PIXELS-PER-INCH-RESOLUTION: 1 export PIXELS-PER-CENTIMETER-RESOLUTION: 2 protect/words [ PIXELS-PER-INCH-RESOLUTION PIXELS-PER-CENTIMETER-RESOLUTION ] and then just use: SomeFunc PIXELS-PER-CENTIMETER-RESOLUTION or SomeFunc 1 with the correct int bound check in the command so only valid numbers are processed. I really like what is possible with R3.. I should start real coding in it soon. | |
Hm.. maybe it's too soon.. the protect seems to be not working if used in the extension's init. I can change the values:/ | |
CC: http://curecode.org/rebol3/ticket.rsp?id=1786 | |
hm.. the protect above is not required anyway as long as there is the validity check in the command. | |
ChristianE 1-Dec-2010 [1810] | Here's how I explained to myself how things went: With A102, the time I started playing around with extensions, there was this RL_FIND_WORD which is supposed to map words against an "extension local" word block. But sadly, I never got that working. It was the "temp hack" comment from which I concluded that the preferred method then became RL_MAP_WORD, which maps a word to a global word id, hence the 1381 number you've got yesterday. With that, you don't need to ENUM in your code but can just compare words supplied with words known. But, I may be totally off track with that reasoning ... wouldn't take me any wonder :-) |
Cyphre 1-Dec-2010 [1811] | Guys, I put the comment about 'temp hack' couple of months ago when I discussed this issue with Carl. Not sure but the init-words trick will probably stay as is because it works fine that way. Ofcourse I may be wrong if there is some better method and Carl decides differently. |
ChristianE 2-Dec-2010 [1812] | Ah, good, to know. So I'm off track indeed, I was expecting that. |
Oldes 5-Dec-2010 [1813] | When I have: #if defined(_WIN64) # define ssize_t __int64 #else # define ssize_t long #endif and function which arg is ssize_t type, how I should get the right value from REBOL in command? Is this correct?: (ssize_t)RXA_INT64(frm, 1)) |
Andreas 5-Dec-2010 [1814] | Yes, Oldes. |
Oldes 5-Dec-2010 [1815x7] | When I have func's arg: void *pixels which should be pointer to allocated binary buffer, how to provide it from the REBOL side? |
Using just RXA_SERIES(frm, 1) does not work. | |
RL_GET_STRING(RXA_SERIES(frm, 1), 0 , (void**)&pixels); doesn't work as well... I think we need RL_GET_BINARY macro... | |
hm... it must be something like: | |
REBYTE *pixels = ((REBYTE *)RL_SERIES((RXA_ARG(frm,7).series), RXI_SER_DATA)); | |
but still miss something important. | |
I'm so stupid! I was testing on wrong data all the time.. the last one is correct:) | |
Andreas 5-Dec-2010 [1822] | Fine that it works :) |
Oldes 5-Dec-2010 [1823x3] | I just would like to know if it's possible for example to change the series tail on C side (and to avoid a need to init the series on REBOL side). |
because now I must do for example this: pixels: make binary! num insert/dup pixels #{00} num before I can use the value in C | |
(I can use it in C without the insert, but I get empty script back to REBOL - there must be updated the TAIL) | |
Andreas 5-Dec-2010 [1826] | Would have to try again, but as far as I remember, RL_SET_VALUE would update the tail. |
Oldes 6-Dec-2010 [1827x2] | When I have func which require something like: double *distortion so it modifies the value of existing REBOL variable, how to do it? |
I know I could just do it with different approach, but I'm still in a learning phase. | |
Cyphre 6-Dec-2010 [1829] | I think you cannot modify such rebol value directly. You have to return it by the command! function. |
Oldes 6-Dec-2010 [1830] | That's the approach I was thinking about. It probably makes a sense as REBOL internal storage may differ. |
BrianH 6-Dec-2010 [1831] | For one thing, REBOL storage is made up of 128bit variant value slots. |
Oldes 6-Dec-2010 [1832] | But I would like to know, if I can just change the provided variable without returning it back as a command result. (as it's possible with series). |
Cyphre 6-Dec-2010 [1833] | yes, for example you never know where the decimal! is in the memory...it can be even just on the stack so or can be GCed so I think it is unsafe to just modify it on the C side and then rely that it'll be reflected on the REBOL side without explicit returned value. |
BrianH 6-Dec-2010 [1834] | All value slots are either in blocks, objects or function contexts (using the generic terms). There are no free value slots. |
Cyphre 6-Dec-2010 [1835] | Oldes, the different situation is for series values (string, image, block...) though. You can directly modify them and use RL_Protect_GC() to make sure GC won't mess with your changes. |
BrianH 6-Dec-2010 [1836] | And you don't have to worry about the GC collecting a double since it will always be in a value slot, so all you have to do is protect the series or context it is in. |
Cyphre 6-Dec-2010 [1837] | Brian, I'm not sure about that. IIRC the value slot of double passed as command! arg is just on the 'function command frame' at the time the command! is executed so it is a copy of the real value you are refering to. |
BrianH 6-Dec-2010 [1838] | He was asking about changing the original. The only way to do that is to pass a reference to the series or context that contains the original value slot. |
Oldes 6-Dec-2010 [1839] | if the frame is just a copy, is it possible to get the original? |
Cyphre 6-Dec-2010 [1840] | yes, that's correct. I though he want's to do something like: d: 0.0 change-decimal d probe d == 1.234 |
BrianH 6-Dec-2010 [1841] | The frame is just another set of value slots that the values are copied into. You can only get the original by passing a reference to the value slot container. There are no free value slots. |
Oldes 6-Dec-2010 [1842] | yes.. that's what I wanted to do:) |
Cyphre 6-Dec-2010 [1843x2] | (whic is not possible) |
yes, that won't work for you | |
Oldes 6-Dec-2010 [1845] | ok |
Cyphre 6-Dec-2010 [1846x4] | because the arg passed to the command function is just a copy of the real value |
you need to return it | |
or as Brian said you could do: d: [0.0] change-decimal d probe d/1 == 1.234 | |
(but you should be using the protext_GC function to be safe) | |
Oldes 6-Dec-2010 [1850x2] | better to avoid it. |
but it a little bit complicates the automatic building of wrappers for functions like that. btw... at this moment I can build imageMagick extension by parsing it's doc (~4500 lines of C code:). Just must solve a few functions where it's using this approach to return multiple values and add some validity checks to make the extension safer. | |
older newer | first last |