How do you use #call directive for Red function with string datatypes as parameters?

kealist

Given a script, such as below, which does not compile yet, how can I use #call to use my Red function from within Red/System?

Red []

pff: function [a [string!] ][print a]  

#system [
    #call [pff "hello"]    
]

There is a type mismatch. What do you need to do to convert the string to the proper Red/System datatype?

DocKimbel

To expand on Peter's correct answer, in this particular case, you need to internalize the c-string as a red-string!, using string/load, like this:

Red []

pff: function [a [string!] ][print a]  

#system [
    s: "hello"
    hello: string/load s 1 + length? s UTF-8
    #call [pff hello]
]

Notes:

  • Red/System's strings are ASCII only for now, so you need to specify UTF-8 as the source encoding format.

  • You need to pass the size of the c-string accounting for the terminal NUL (hence the + 1).

The internal API is not documented as it is not finalized. Feel free to ask here or on our other communication channels if you need any info about it.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How to use call function?

来自分类Dev

What do you call this and how to read this? (Parsing for Scheme)

来自分类Dev

How do you declare a function in which you pass a multidimensional array by reference

来自分类Dev

String changes after function call

来自分类Dev

How do you call C++ and\or Java functions from Python 2.7?

来自分类Dev

How do I use a Codeigniter method within my own function?

来自分类Dev

How do I use an extension function in another class? C#

来自分类Dev

ironpython: How to call a chm Helpfile on Windows with parameters

来自分类Dev

When merging objects using Newtonsoft.Json, how do you ignore empty string values?

来自分类Dev

How do you supply a default value to a string option in Options.Applicative

来自分类Dev

How do you “update” a stash?

来自分类Dev

Do you need to call dispatch_group_release under ARC?

来自分类Dev

Updates controller-value and call controller-function from a directive. controller-calue not updated before function is called

来自分类Dev

How to pass in parameters when use resource service?

来自分类Dev

How do you declare a global constant in Python?

来自分类Dev

How would you do this tricky subsetting in R?

来自分类Dev

How do You Build an RSS feed with Jade?

来自分类Dev

How do you initialize and present a custom SLComposeServiceViewController?

来自分类Dev

How do you convert a dictionary to a ConcurrentDictionary?

来自分类Dev

How do you sort list of strings in batch?

来自分类Dev

How do you round decimal of an expression in mathematica

来自分类Dev

How do you match a trait in rust?

来自分类Dev

How do you stop a bash shell expansion?

来自分类Dev

rebol --do 和 red --do

来自分类Dev

How to call a function with a reference to an unknown size array?

来自分类Dev

How do I implement a CString hash function for use with std::unordered_map?

来自分类Dev

How do I get all the values of a String array to use in a return statement in a method?

来自分类Dev

I have a few function overloads, each of which takes a different subclass; how do I check which function to use for a given object?

来自分类Dev

Using jquery how to call a function and call another function from the previous when function execution is completed

Related 相关文章

  1. 1

    How to use call function?

  2. 2

    What do you call this and how to read this? (Parsing for Scheme)

  3. 3

    How do you declare a function in which you pass a multidimensional array by reference

  4. 4

    String changes after function call

  5. 5

    How do you call C++ and\or Java functions from Python 2.7?

  6. 6

    How do I use a Codeigniter method within my own function?

  7. 7

    How do I use an extension function in another class? C#

  8. 8

    ironpython: How to call a chm Helpfile on Windows with parameters

  9. 9

    When merging objects using Newtonsoft.Json, how do you ignore empty string values?

  10. 10

    How do you supply a default value to a string option in Options.Applicative

  11. 11

    How do you “update” a stash?

  12. 12

    Do you need to call dispatch_group_release under ARC?

  13. 13

    Updates controller-value and call controller-function from a directive. controller-calue not updated before function is called

  14. 14

    How to pass in parameters when use resource service?

  15. 15

    How do you declare a global constant in Python?

  16. 16

    How would you do this tricky subsetting in R?

  17. 17

    How do You Build an RSS feed with Jade?

  18. 18

    How do you initialize and present a custom SLComposeServiceViewController?

  19. 19

    How do you convert a dictionary to a ConcurrentDictionary?

  20. 20

    How do you sort list of strings in batch?

  21. 21

    How do you round decimal of an expression in mathematica

  22. 22

    How do you match a trait in rust?

  23. 23

    How do you stop a bash shell expansion?

  24. 24

    rebol --do 和 red --do

  25. 25

    How to call a function with a reference to an unknown size array?

  26. 26

    How do I implement a CString hash function for use with std::unordered_map?

  27. 27

    How do I get all the values of a String array to use in a return statement in a method?

  28. 28

    I have a few function overloads, each of which takes a different subclass; how do I check which function to use for a given object?

  29. 29

    Using jquery how to call a function and call another function from the previous when function execution is completed

热门标签

归档