aerospike / aerospike-client-java

Aerospike Java Client Library
Other
236 stars 212 forks source link

Cannot call lua method load #50

Closed Osguima3 closed 8 years ago

Osguima3 commented 9 years ago

This lua method is not available in this client, while other clients, like the node.js one, do. We use this method to dynamically generate aggregation functions.

I was able to use this method by previously registering it manually so that Aerospike gets an instance with the method loaded. (This is a hacky way, probably there is a better one):

final LuaInstance instance = LuaCache.getInstance();
instance.registerPackage("load", LuaTable.tableOf(new LuaValue[] {
    LuaValue.valueOf("loadLib"), JsePlatform.standardGlobals().get("load") }));
LuaCache.putInstance(instance);

and then in lua

local load = load or loadLib.load
local foo = load("return 'hi'");
info(foo()); -- Prints 'hi'

But this doesn't solve the problem if Aerospike decides it needs more instances than what the pool currently has.

Osguima3 commented 9 years ago

I researched a bit more, and all that would be needed is:

import org.luaj.vm2.LoadState;

public LuaInstance() throws AerospikeException {
   ...
   LoadState.install(globals);
}
BrianNichols commented 9 years ago

We will add "LoadState.install(globals);" at the end of the LuaInstance constructor in the next java client release.

BrianNichols commented 8 years ago

Java client has been released.