1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

mod key;
use key::*;

static SAMPLE:Class = Class::uninit();

fn test(args:Vec<LitrRef>)->Litr {
  println!("示例函数:{:?}", &*args[0]);
  Litr::Uninit
}
fn sample_new(_args:Vec<LitrRef>)-> Litr {
  let inst = SAMPLE.create(0, 15);
  inst
}
fn sample_see(v:&mut Instance, _args:Vec<LitrRef>)-> Litr {
  println!("{} {}", v.v1, v.v2);
  Litr::Uninit
}
fn sample_getter(_v:&mut Instance, get:Interned)-> Litr {
  println!("dll get: {get}");
  Litr::Uninit
}
fn sample_setter(_v:&mut Instance, set:Interned, to:Litr) {
  println!("dll set: {set}, {to:?}");
}

pub fn main(module: &mut NativeInterface) {
  SAMPLE.new("Sample");
  module.export_cls(SAMPLE.clone());
  SAMPLE.onclone(|v|{
    println!("cloned!");
    v.clone()
  });
  SAMPLE.next(|v|{
    if v.v2<v.v1 {
      return Symbol::iter_end();
    }
    let res = Litr::Uint(v.v1);
    v.v1 += 1;
    res
  });
  SAMPLE.index_get(|_v,i|{
    println!("get:[{:?}]",&*i);
    Litr::Float(2.55)
  });
  SAMPLE.index_set(|_v,i,val|{
    println!("set:[{:?}] = {:?}", &*i, &*val);
  });
  SAMPLE.onclone(|v|{
    println!("clone!");
    v.clone()
  });
  SAMPLE.ondrop(|_|{
    println!("drop!");
  });
  SAMPLE.static_method("new", sample_new);
  SAMPLE.method("see", sample_see);
  SAMPLE.getter(sample_getter);
  SAMPLE.setter(sample_setter);
  module.export_fn("test", test);
}