While trying to solve the question How to print a sqlite table content with genie programming language I found out that I could try to call PrintSingleRecipe as a callback from Database.exec. However, it seems that a callback cannot be a regular function, they have some property that I do not seem to find over in the internets.
I am calling it in this way:
else if response is "3" //Show a Recipe
res:string = UserInterface.raw_input("Select a recipe -> ")
sql:string = "SELECT * FROM Recipes WHERE pkID = %res"
db.exec(sql, PrintSingleRecipe, null)
And the function itself looks like:
def PrintSingleRecipe(n_columns:int, values:array of string, column_names:array of string)
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
for i:int = 0 to n_columns
stdout.printf ("%s = %s\n", column_names[i], values[i])
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "Ingredient list"
print " "
stdout.printf("%-5s", "%03i" )
However, I get the following error at compilation:
valac --pkg sqlite3 --pkg gee-0.8 cookbook.gs
cookbook.gs:42.26-42.42: error: Argument 2: Cannot convert from `PrintSingleRecipe' to `Sqlite.Callback?'
db.exec(sql, PrintSingleRecipe, null)
^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
How to properly run the callback in Genie?