Skip to content

Commit

Permalink
add constants casting for parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
scorninpc committed May 10, 2022
1 parent 3a47a9b commit a6533f5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gen/defs.txt
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
37 changes: 26 additions & 11 deletions gen/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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":
Expand All @@ -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;
}

}
Expand All @@ -128,6 +136,10 @@ static public function parseParam($count, $param)
"GtkWindow" => "GtkWidget",
];

$existing_constants = [
"GtkJustification" => TRUE,
];

$def_functions = [];
$def_classes = [];

Expand Down Expand Up @@ -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' => [],
];

Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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 &parameters";
Expand Down

0 comments on commit a6533f5

Please sign in to comment.