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).

!752

sS suckerID = "#1004698";

static interface Algorithm {
  S predict(int max);
  void feed(S s);
}

// simple test algorithm
sS lua = [[
function p(m, s)
  if s ~= nil then c = s:sub(s:len()) end
  return c
end
]];

static O sucker;

p {
  wakeSucker(suckerID, "L " + trim(lua), new LuaAlgo(trim(lua)));
  
  fixContextClassLoader();
  luaCompile(true);
  
  wakeSucker(suckerID, "L " + trim(lua), new LuaAlgo(trim(lua)));
  cleanUp(sucker);
}

static void wakeSucker(S suckerID, S desc, Algorithm algo) {
  ping();

  if (sucker == null) {
    print("Waking...");
    sucker = run(suckerID);
  }
  print("Feeding...");
  
  Class intrface = getClass(sucker, "main$Algorithm");
  assertNotNull("main$Algorithm", intrface);
  O proxy = proxy(intrface, algo);
  O result = callOpt(sucker, "suck", desc, proxy);
  print("Suck Result: " + struct(result));
}

static class LuaAlgo implements Algorithm {
  LuaValue predict, feed;
  S feeding;
  
  *(S code) {
    Sandbox s = luaSandbox();
    evalLua(s, code);
    //print("KEYS: " + structure(s.keys()));
    predict = s.get("predict");
    if (predict.isnil()) predict = s.get("p");
    assertFalse(predict.isnil());
  }
  
  public S predict(int max) {
    LuaValue s = predict.call(Lua.value(max), feeding != null ? Lua.value(feeding) : Lua.NIL);
    feeding = null;
    ret s.isnil() ? "" : s.tojstring();
  }
  
  public void feed(S s) {
    feeding = s;
  }
}

static Algorithm makeAlgo(S desc) {
  assertStartsWith(desc, "L ");
  ret new LuaAlgo(desc.substring(2));
}

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: 575 / 655
Referenced in: [show references]