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

73
LINES

< > BotCompany Repo | #1004701 // Feed Text Predict Sucker With LUA [Early Spike]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 5262K of libraries. Click here for Pure Java version (1467L/10K/34K).

1  
!752
2  
3  
sS suckerID = "#1004698";
4  
5  
static interface Algorithm {
6  
  S predict(int max);
7  
  void feed(S s);
8  
}
9  
10  
// simple test algorithm
11  
sS lua = [[
12  
function p(m, s)
13  
  if s ~= nil then c = s:sub(s:len()) end
14  
  return c
15  
end
16  
]];
17  
18  
static O sucker;
19  
20  
p {
21  
  wakeSucker(suckerID, "L " + trim(lua), new LuaAlgo(trim(lua)));
22  
  
23  
  fixContextClassLoader();
24  
  luaCompile(true);
25  
  
26  
  wakeSucker(suckerID, "L " + trim(lua), new LuaAlgo(trim(lua)));
27  
  cleanUp(sucker);
28  
}
29  
30  
static void wakeSucker(S suckerID, S desc, Algorithm algo) {
31  
  ping();
32  
33  
  if (sucker == null) {
34  
    print("Waking...");
35  
    sucker = run(suckerID);
36  
  }
37  
  print("Feeding...");
38  
  
39  
  Class intrface = getClass(sucker, "main$Algorithm");
40  
  assertNotNull("main$Algorithm", intrface);
41  
  O proxy = proxy(intrface, algo);
42  
  O result = callOpt(sucker, "suck", desc, proxy);
43  
  print("Suck Result: " + struct(result));
44  
}
45  
46  
static class LuaAlgo implements Algorithm {
47  
  LuaValue predict, feed;
48  
  S feeding;
49  
  
50  
  *(S code) {
51  
    Sandbox s = luaSandbox();
52  
    evalLua(s, code);
53  
    //print("KEYS: " + structure(s.keys()));
54  
    predict = s.get("predict");
55  
    if (predict.isnil()) predict = s.get("p");
56  
    assertFalse(predict.isnil());
57  
  }
58  
  
59  
  public S predict(int max) {
60  
    LuaValue s = predict.call(Lua.value(max), feeding != null ? Lua.value(feeding) : Lua.NIL);
61  
    feeding = null;
62  
    ret s.isnil() ? "" : s.tojstring();
63  
  }
64  
  
65  
  public void feed(S s) {
66  
    feeding = s;
67  
  }
68  
}
69  
70  
static Algorithm makeAlgo(S desc) {
71  
  assertStartsWith(desc, "L ");
72  
  ret new LuaAlgo(desc.substring(2));
73  
}

Author comment

Began life as a copy of #1004699

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: #1004701
Snippet name: Feed Text Predict Sucker With LUA [Early Spike]
Eternal ID of this version: #1004701/1
Text MD5: 8e02fc3fce17048b35f654fac67d87d0
Transpilation MD5: 735cea1908499bd4162c71b113449a18
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-27 22:41:15
Source code size: 1598 bytes / 73 lines
Pitched / IR pitched: No / No
Views / Downloads: 580 / 662
Referenced in: [show references]