Posted 19 April 2012 - 09:33 PM
Hi,
The one thing I dislike about the peripheral library is that it is too far away from lua. you can only return/use as args the primitive values number, string, boolean and nil, but not the advanced types like tables or userdata. I know of some alternatives, but they are impractical. The result of this is the need of a separate lua api file to allow convenient use and a large amount of code that wouldn't be needed otherwise. Just one example from my AIP database peripheral:
Actual logical code:
If I would be able to use userdata/tables directly, this would be much shorter. There would also not be much need for a seperate api.
So, to make it short, in my opinion the peripheral.call method should use the luaj values, not the badly masked version.
The one thing I dislike about the peripheral library is that it is too far away from lua. you can only return/use as args the primitive values number, string, boolean and nil, but not the advanced types like tables or userdata. I know of some alternatives, but they are impractical. The result of this is the need of a separate lua api file to allow convenient use and a large amount of code that wouldn't be needed otherwise. Just one example from my AIP database peripheral:
Actual logical code:
for (Iterator it = recipeList.iterator(); it.hasNext():)/>/> {
IRecipe recipe = (IRecipe) it.next();
ItemStack rres = recipe.getRecipeOutput();
if (stack.isItemEqual(rres)) {
Object[] recipeData;
boolean shapeless = false;
int width = 0;
if (recipe instanceof ShapedRecipes) {
recipeData = (Object[]) getField(recipe,
ShapedRecipes.class, "d");
width = ((Integer) getField(recipe,
ShapedRecipes.class, "b"));
} else {
shapeless = true;
recipeData = ((List) getField(recipe,
ShapelessRecipes.class, "b")).toArray();
}
Overhead because of lack of userdata:
StringBuilder result = new StringBuilder();
result.append("{\n");
...
result.append("\t{\n");
int j = 0;
for (int i = 0; i < recipeData.length; i++) {
ItemStack st = (ItemStack) recipeData[i];
if (st == null) {
result.append("\t\tnil,\n");
} else {
result.append("\t\tdb.getItem(\"");
result.append(getName(st));
result.append("\"),\n");
}
// Adjust shaped recipe outline
j++;
if (!shapeless && (j % 3) == width) {
while (j % 3 != 0) {
result.append("\t\tnil,\n");
j++;
}
}
}
result.append("\t\tshapeless = ");
result.append(shapeless);
result.append("\n\t},\n");
}
}
result.append("}");
And some more.If I would be able to use userdata/tables directly, this would be much shorter. There would also not be much need for a seperate api.
So, to make it short, in my opinion the peripheral.call method should use the luaj values, not the badly masked version.