view core/src/luan/modules/ThreadLuan.java @ 360:cbb94a7c7a9e

allow mail attachments; add String.to_binary and Binary.to_string;
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 15 Apr 2015 11:32:30 -0600
parents a6bf8ff720f8
children c6bcb8859b93
line wrap: on
line source

package luan.modules;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import luan.Luan;
import luan.LuanState;
import luan.LuanFunction;
import luan.LuanTable;
import luan.LuanException;
import luan.DeepCloner;


public final class ThreadLuan {
	private static final Executor exec = Executors.newCachedThreadPool();

	public static void fork(LuanState luan,LuanFunction fn,Object... args) {
		DeepCloner cloner = new DeepCloner();
		final LuanState newLuan = cloner.deepClone(luan);
		final LuanFunction newFn = cloner.get(fn);
		final Object[] newArgs = cloner.deepClone(args);
		exec.execute(new Runnable(){public void run() {
			try {
				newLuan.call(newFn,"<forked>",newArgs);
			} catch(LuanException e) {
				e.printStackTrace();
			}
		}});
	}
}