Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1004709 // makeLuaTextPredictAlgo

JavaX fragment (include)

1  
static interface Algorithm {
2  
  S predict(int max);
3  
  void feed(S s);
4  
}
5  
6  
static class LuaAlgo implements Algorithm {
7  
  LuaValue predict, feed;
8  
  S feeding;
9  
  
10  
  *(S code) {
11  
    Sandbox s = luaSandbox();
12  
    evalLua(s, code);
13  
    //print("KEYS: " + structure(s.keys()));
14  
    predict = s.get("predict");
15  
    if (predict.isnil()) predict = s.get("p");
16  
    assertFalse(predict.isnil());
17  
  }
18  
  
19  
  public S predict(int max) {
20  
    LuaValue s = predict.call(Lua.value(max), feeding != null ? Lua.value(feeding) : Lua.NIL);
21  
    feeding = null;
22  
    ret s.isnil() ? "" : s.tojstring();
23  
  }
24  
  
25  
  public void feed(S s) {
26  
    feeding = s;
27  
  }
28  
}
29  
30  
static Algorithm makeLuaTextPredictAlgo(S desc) {
31  
  ret new LuaAlgo(dropPrefix("L ", desc));
32  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004709
Snippet name: makeLuaTextPredictAlgo
Eternal ID of this version: #1004709/1
Text MD5: 67feb78e11c7696b4572fb21d02c8900
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-28 15:49:57
Source code size: 756 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 575 / 604
Referenced in: [show references]