use of buildcraft.lib.expression.api.INodeFunc.INodeFuncDouble in project BuildCraft by BuildCraft.
the class InternalCompiler method addParentFunctions.
private static String addParentFunctions(FunctionContext context) {
String vars = "";
List<String> allFunctions = new ArrayList<>();
allFunctions.addAll(context.getAllFunctions().keySet());
allFunctions.sort(Comparator.naturalOrder());
if (!allFunctions.isEmpty()) {
if (!context.name.isEmpty()) {
vars += "\n" + context.name + ":";
}
for (String fnName : allFunctions) {
Map<List<Class<?>>, INodeFunc> functions = context.getFunctions(fnName);
for (Map.Entry<List<Class<?>>, INodeFunc> entry : functions.entrySet()) {
String args = "";
for (Class<?> arg : entry.getKey()) {
if (args.length() > 0) {
args += ", ";
}
args += NodeTypes.getName(arg);
}
INodeFunc function = entry.getValue();
String ret;
if (function instanceof INodeFuncBoolean) {
ret = NodeTypes.getName(boolean.class);
} else if (function instanceof INodeFuncDouble) {
ret = NodeTypes.getName(double.class);
} else if (function instanceof INodeFuncLong) {
ret = NodeTypes.getName(long.class);
} else {
ret = NodeTypes.getName(((INodeFuncObject<?>) function).getType());
}
vars += "\n " + fnName + "(" + args + ") -> " + ret;
}
}
}
for (FunctionContext parent : context.getParents()) {
vars += addParentFunctions(parent);
}
return vars;
}
use of buildcraft.lib.expression.api.INodeFunc.INodeFuncDouble in project BuildCraft by BuildCraft.
the class NodeCasting method castToDouble.
public static INodeFuncDouble castToDouble(INodeFunc func) throws InvalidExpressionException {
if (func instanceof INodeFuncDouble) {
return (INodeFuncDouble) func;
}
Class<?> type = NodeTypes.getType(func);
FunctionContext ctx = NodeTypes.getContext(type);
if (ctx == null) {
throw new InvalidExpressionException("Cannot cast " + func + " to a double!");
}
INodeFunc caster = ctx.getFunction("(double)", Collections.singletonList(type));
if (caster == null || NodeTypes.getType(caster) != double.class) {
throw new InvalidExpressionException("Cannot cast " + func + " to a double!");
}
return (stack) -> (INodeDouble) caster.getNode(new NodeStack(func.getNode(stack)));
}
Aggregations