Skip to main content

js

Function js 

Source
pub unsafe extern "C" fn js(list: *mut K, symbol: S) -> K
Expand description

Add an enumerated character array to a symbol list. Returns a pointer to the (potentially reallocated) K object.

§Example

#[macro_use]
extern crate kdbplus;
use kdbplus::qtype;
use kdbplus::api::*;
use kdbplus::api::native::*;

#[no_mangle]
pub extern "C" fn create_symbol_list(_: K) -> K{
  unsafe{
    let mut list=ktn(qtype::SYMBOL_LIST as I, 0);
    js(&mut list, ss(str_to_S!("Abraham")));
    js(&mut list, ss(str_to_S!("Isaac")));
    js(&mut list, ss(str_to_S!("Jacob")));
    js(&mut list, sn(str_to_S!("Josephine"), 6));
    list
  }
}
q)summon:`libc_api_examples 2: (`create_symbol_list; 1)
q)summon[]
`Abraham`Isaac`Jacob`Joseph
q)`Abraham`Isaac`Jacob`Joseph ~ summon[]
1b

§Note

In this example we did not allocate an array as ktn(qtype::SYMBOL_LIST as I, 0) to use js. As ktn initializes the internal list size n with its argument, preallocating memory with ktn and then using js will crash. If you want to allocate a memory in advance, you can substitute a value after converting the q list object into a slice with as_mut_slice.