本文整理汇总了Java中org.luaj.vm2.LuaFunction类的典型用法代码示例。如果您正苦于以下问题:Java LuaFunction类的具体用法?Java LuaFunction怎么用?Java LuaFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LuaFunction类属于org.luaj.vm2包,在下文中一共展示了LuaFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
public LuaValue call(LuaValue value, LuaValue table) {
LuaValue mt = table.opttable(null);
switch (value.type()) {
case TNIL:
LuaNil.s_metatable = mt;
break;
case TNUMBER:
LuaNumber.s_metatable = mt;
break;
case TBOOLEAN:
LuaBoolean.s_metatable = mt;
break;
case TSTRING:
LuaString.s_metatable = mt;
break;
case TFUNCTION:
LuaFunction.s_metatable = mt;
break;
case TTHREAD:
LuaThread.s_metatable = mt;
break;
default:
value.setmetatable(mt);
}
return value;
}
示例2: funcinfo
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
public void funcinfo(LuaFunction f) {
if (f.isclosure()) {
Prototype p = f.checkclosure().p;
this.source = p.source != null ? p.source.tojstring() : "=?";
this.linedefined = p.linedefined;
this.lastlinedefined = p.lastlinedefined;
this.what = (this.linedefined == 0) ? "main" : "Lua";
this.short_src = p.shortsource();
} else {
this.source = "=[Java]";
this.linedefined = -1;
this.lastlinedefined = -1;
this.what = "Java";
this.short_src = f.name();
}
}
示例3: sprite
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
/**
* 创建一个切片
*
* @param x
* @param y
* @param width
* @param height
* @param callback
* @return
*/
public LuaValue sprite(final int x, final int y, final int width, final int height, final LuaFunction callback) {
if (callback != null) {
new SimpleTask1<LuaValue>() {
@Override
protected LuaValue doInBackground(Object... params) {
return createSprite(x, y, width, height);
}
@Override
protected void onPostExecute(LuaValue luaValue) {
LuaUtil.callFunction(callback, luaValue);
}
}.executeInPool();
return LuaValue.NIL;
} else {
return createSprite(x, y, width, height);
}
}
示例4: setImageUrlAsync
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
private void setImageUrlAsync(final T imageView, final String urlOrName, final LuaFunction callback) {
if (getLuaResourceFinder() != null) {//异步加载图片
getLuaResourceFinder().findDrawable(urlOrName, new LuaResourceFinder.DrawableFindCallback() {
@Override
public void onStart(String urlOrPath) {
if (imageView != null && urlOrName != null) {
imageView.setTag(Constants.RES_LV_TAG_URL, urlOrName);
}
}
@Override
public void onFinish(Drawable drawable) {
if (imageView != null && urlOrName != null && urlOrName.equals(imageView.getTag(Constants.RES_LV_TAG_URL))) {
imageView.setImageDrawable(drawable);
}
if (callback != null) {//本地图片直接调用callback
LuaUtil.callFunction(callback, drawable != null ? LuaBoolean.TRUE : LuaBoolean.FALSE);
}
}
});
}
}
示例5: run
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
@Override
public void run(String name, Object... parameter) {
LuaFunction function = lua.getFunction(name);
if (parameter.length == 0) {
function.call();
} else {
if (parameter.length == 1) {
function.call(CoerceJavaToLua.coerce(parameter[0]));
}
if (parameter.length == 2) {
function.call(CoerceJavaToLua.coerce(parameter[0]), CoerceJavaToLua.coerce(parameter[1]));
}
if (parameter.length == 3) {
function.call(CoerceJavaToLua.coerce(parameter[0]), CoerceJavaToLua.coerce(parameter[1]),
CoerceJavaToLua.coerce(parameter[2]));
}
if (parameter.length > 3) {
throw new RuntimeException("Too many parameters in Lua function call: " + name);
}
}
}
示例6: funcinfo
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
public void funcinfo(LuaFunction f) {
if (f.isclosure()) {
Prototype p = f.checkclosure().p;
this.source = p.source != null ? p.source.tojstring() : "=?";
this.linedefined = p.linedefined;
this.lastlinedefined = p.lastlinedefined;
this.what = (this.linedefined == 0) ? "main" : "Lua";
this.short_src = p.shortsource();
} else {
this.source = "=[Java]";
this.linedefined = -1;
this.lastlinedefined = -1;
this.what = "Java";
this.short_src = f.name();
}
}
示例7: method
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
@RuntimeType
public Object method(@Origin Method aMethod, @This Object o, @AllArguments Object[] objects,
@SuperCall Callable supercall) {
LuaValue value = delegations.get(aMethod.getName());
if (value.isnil()) {
try {
return supercall.call();
} catch (Exception e) {
throw new DynamicDelegationError("Supercall threw exception - no delegation supplied", e);
}
}
if (value.isfunction()) {
LuaFunction function = value.checkfunction();
LuaValue[] parameters = convertParamsToLua(o, objects, supercall);
Varargs invoke = function.invoke(parameters);
if (aMethod.getReturnType() == Void.class || invoke.narg() == 0)
return null;
return LuaConversion.convertToJava(aMethod.getReturnType(), invoke.checkvalue(1));
} else {
return LuaConversion.convertToJava(aMethod.getReturnType(), value);
}
}
示例8: LuaModInstance
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
public LuaModInstance(String name, FileHandle file, AssetManager assetManager, Map<String, FileHandle> luaFiles, FileHandle luaFolder) {
super(name, file, assetManager);
this.luaFiles = luaFiles;
this.luaFolder = luaFolder;
this.modStates = new ArrayList<ModState>();
this.globals = CubesLua.globals(); // each mod has its own globals
this.luaModEvent = new Multimap<ModState, LuaFunction>();
this.clientEventListeners = new ArrayList<LuaEventListener>();
this.serverEventListeners = new ArrayList<LuaEventListener>();
int length = Integer.MAX_VALUE;
String current = luaFiles.keySet().iterator().next();
for (Entry<String, FileHandle> entry : luaFiles.entrySet()) {
String s = entry.getKey();
if (s.toLowerCase().contains("init") && s.length() < length) {
length = s.length();
current = s;
}
}
initFile = name + "|" + current;
Log.debug("Using '" + initFile + "' as init file");
}
示例9: invoke
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
public Varargs invoke(Varargs args) {
String name = args.checkjstring(1);
String classname = toClassname( name );
Class c = null;
LuaValue v = null;
try {
c = Class.forName(classname);
v = (LuaValue) c.newInstance();
if (v.isfunction())
((LuaFunction)v).initupvalue1(globals);
return varargsOf(v, globals);
} catch ( ClassNotFoundException cnfe ) {
return valueOf("\n\tno class '"+classname+"'" );
} catch ( Exception e ) {
return valueOf("\n\tjava load failed on '"+classname+"', "+e );
}
}
示例10: off
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
public LuaValue off(LuaValue entity, LuaValue eventName, LuaValue callback) {
RpgPlusEntity managedEntity = ScriptUtil.getManagedEntity(entity, true);
if (eventName.isnil()) {
return LuaValue.valueOf(!eventHandlers.remove(managedEntity).isEmpty());
} else {
Multimap<String, LuaFunction> handlers = eventHandlers.get(managedEntity);
if (handlers != null) {
if (callback.isnil()) {
return LuaValue.valueOf(!handlers.removeAll(eventName.checkjstring()).isEmpty());
} else {
return LuaFunction.valueOf(handlers.remove(eventName.checkjstring(), callback.checkfunction()));
}
} else {
return LuaValue.FALSE;
}
}
}
示例11: off
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
public LuaValue off(LuaValue inventoryWrapper, LuaValue eventName, LuaValue callback) {
if (inventoryWrapper instanceof InventoryWrapper) {
Inventory inventory = ((InventoryWrapper) inventoryWrapper).getInventory();
if (eventName.isnil()) {
return LuaValue.valueOf(!eventHandlers.remove(inventory).isEmpty());
} else {
Multimap<String, LuaFunction> handlers = eventHandlers.get(inventory);
if (handlers != null) {
if (callback.isnil()) {
return LuaValue.valueOf(!handlers.removeAll(eventName.checkjstring()).isEmpty());
} else {
return LuaFunction.valueOf(handlers.remove(eventName.checkjstring(), callback.checkfunction()));
}
} else {
return LuaValue.FALSE;
}
}
}else {
throw new LuaError("Not an inventory");
}
}
示例12: processScript
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
private static void processScript(InputStream script, String chunkname, String[] args, int firstarg)
{
try
{
LuaFunction c;
try
{
c = LuaC.load(script, chunkname, _G);
}
finally
{
script.close();
}
Varargs scriptargs = (args != null ? setGlobalArg(args, firstarg) : LuaValue.NONE);
c.invoke(scriptargs);
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
}
示例13: call
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
public void call(String functionPath, Object[] arguments)
{
String[] segm = functionPath.split("\\.");
LuaTable table = globals;
for (int i = 0; i < segm.length - 1; i++)
{
LuaValue newTable = table.get(segm[i]);
table = newTable.checktable();
}
LuaValue functionValue = table.get(segm[segm.length - 1]);
LuaFunction function = functionValue.checkfunction();
call(function, arguments);
}
示例14: invoke
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
@Override
public Varargs invoke(Varargs args)
{
if ((data.argcexact && args.narg() != data.argc) || (!data.argcexact && args.narg() < data.argc))
throw new LuaError("invalid argument count to Lime function \"" + data.name + "\"");
switch (data)
{
case ADD_EVENT_LISTENER:
{
String eventName = args.arg(1).checkstring().tojstring();
LuaFunction callback = args.arg(2).checkfunction();
int hash = HashHelper.hash32(eventName);
int listenerID = emanPool.get(hash).addListener(new LuaEventListener(callback));
return LuaValue.valueOf(listenerID);
}
case REMOVE_EVENT_LISTENER:
{
int callbackID = args.arg(1).checkint();
emanPool.remove(callbackID);
break;
}
}
return LuaValue.NONE;
}
示例15: call
import org.luaj.vm2.LuaFunction; //导入依赖的package包/类
@Override
public LuaValue call(LuaValue event, LuaValue identifier, LuaValue function) {
if (!event.isstring() || !identifier.isstring() || !function.isfunction()) {
return FALSE;
}
LuaHandler.getHandler().getHookManager().add(event.tojstring(), identifier.tojstring(), (LuaFunction) function);
return TRUE;
}