From a6533f5a65cc415616007d1fa41844d57e1c7899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Pitteli=20Gon=C3=A7alves?= Date: Mon, 9 May 2022 22:06:41 -0300 Subject: [PATCH] add constants casting for parameters --- gen/defs.txt | 2 +- gen/run.php | 37 ++++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gen/defs.txt b/gen/defs.txt index 9033760..7dc32d4 100644 --- a/gen/defs.txt +++ b/gen/defs.txt @@ -1,4 +1,4 @@ -void gtk_application_add_accelerator (GtkApplication* application, const gchar* accelerator, const gchar* action_name, GVariant* parameter); +void gtk_application_add_accelerator (GtkApplication* application, const gchar* accelerator, GtkJustification action_name, gint parameter); void gtk_application_add_window (GtkApplication* application, GtkWindow* window); diff --git a/gen/run.php b/gen/run.php index b6ea617..ad4081c 100644 --- a/gen/run.php +++ b/gen/run.php @@ -75,6 +75,8 @@ static public function getCleanType($type, $removePointer=TRUE) */ static public function parseParam($count, $param) { + global $existing_constants; + // Remove constant key $clean_param = \PhpConvert::getCleanType($param, FALSE); $tmp = explode(" ", $clean_param); @@ -90,6 +92,7 @@ static public function parseParam($count, $param) case "gchar*": $template_code .= "std::string c_%(param_name)s = parameters[%(param_count)s];\n"; $template_code .= "gchar *%(param_name)s = (gchar *)c_%(param_name)s.c_str();"; + break; // Float case "gfloat": @@ -103,18 +106,23 @@ static public function parseParam($count, $param) case "gboolean": $template_code .= "%(type)s %(param_name)s = (%(type)s)parameters[%(param_count)s];"; break; + + // Others + default: + if(isset($existing_constants[$type])) { + $template_code .= "int c_%(param_name)s = (int)parameters[%(param_count)s];\n"; + $template_code .= "%(type)s %(param_name)s = (%(type)s)c_%(param_name)s;"; + } + } $result_code = \Strings::vsprintf_named($template_code, [ 'param_count' => $count, - 'param_name' => $name + 'param_name' => $name, + 'type' => $type, ]); - die($result_code); - - - - die(); + return $result_code; } } @@ -128,6 +136,10 @@ static public function parseParam($count, $param) "GtkWindow" => "GtkWidget", ]; +$existing_constants = [ + "GtkJustification" => TRUE, +]; + $def_functions = []; $def_classes = []; @@ -239,10 +251,10 @@ class %(class_name)s_ : public %(extends)s_ foreach($def_class as $function_name => $function) { // Store php final infos - $def_classes[$class_name]['php'] = [ + $def_classes[$class_name]['php'][$function_name] = [ 'method_name' => "", 'return_type' => "void", - 'params' => "", + 'params' => [], 'extra_includes' => [], ]; @@ -255,7 +267,7 @@ class %(class_name)s_ : public %(extends)s_ else { $extra_include = "#include \"../" . $tmp[0] . "/" . $existing_classes[$class_name] . ".h\""; } - $def_classes[$class_name]['php']['extra_includes'][$class_name] = $extra_include; + $def_classes[$class_name]['php'][$function_name]['extra_includes'][$class_name] = $extra_include; } // Get class holder. the start name of functions in C @@ -266,7 +278,7 @@ class %(class_name)s_ : public %(extends)s_ // Verify if it's construct if($method_name == "new") { - $def_classes[$class_name]['php']['method_name'] = "__construct"; + $def_classes[$class_name]['php'][$function_name]['method_name'] = "__construct"; // if yes, return void } else { @@ -291,12 +303,15 @@ class %(class_name)s_ : public %(extends)s_ } // Convert the function param to php - $codeConverted = \PhpConvert::parseParam($count, $param); + $def_classes[$class_name]['php'][$function_name]['params'][] = \PhpConvert::parseParam($count, $param); // Next param $count++; } + var_dump("\n\n" . implode("\n\n", $def_classes[$class_name]['php'][$function_name]['params']) . "\n\n"); + die(); + // Verify if there is param if($count > 0) { $method_param = "Php::Parameters ¶meters";