当前位置: 首页>>代码示例>>Java>>正文


Java LuaFunction类代码示例

本文整理汇总了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;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:27,代码来源:DebugLib.java

示例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();
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:17,代码来源:DebugLib.java

示例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);
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:29,代码来源:UDBitmap.java

示例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);
                }
            }
        });
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:24,代码来源:UDImageView.java

示例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);
		}

	}

}
 
开发者ID:hamilton-lima,项目名称:robolucha,代码行数:26,代码来源:LuaScriptDefinition.java

示例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();
	}
}
 
开发者ID:hsllany,项目名称:HtmlNative,代码行数:17,代码来源:DebugLib.java

示例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);
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:23,代码来源:LuaGeneration.java

示例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");
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:24,代码来源:LuaModInstance.java

示例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 );
	}
}
 
开发者ID:Cephrus,项目名称:Elite-Armageddon,代码行数:18,代码来源:PackageLib.java

示例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;
        }
    }
}
 
开发者ID:leMaik,项目名称:RpgPlus,代码行数:18,代码来源:EntityEventManagerImpl.java

示例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");
    }
}
 
开发者ID:leMaik,项目名称:RpgPlus,代码行数:22,代码来源:InventoryEventManagerImpl.java

示例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);
	}
}
 
开发者ID:dwing4g,项目名称:luaj,代码行数:22,代码来源:lua.java

示例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);
}
 
开发者ID:LoDoMa,项目名称:Lime,代码行数:17,代码来源:LuaScript.java

示例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;
}
 
开发者ID:LoDoMa,项目名称:Lime,代码行数:26,代码来源:EventFunctions.java

示例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;
}
 
开发者ID:ImpactDevelopment,项目名称:ClientAPI,代码行数:9,代码来源:hook.java


注:本文中的org.luaj.vm2.LuaFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。