Global templates (alternative concept)

Notice: This is just an alternative concept of what global templates could look like. Currently, a similar function is offered by Wikifunctions, and the concept of global templates is an alias for Wikifunctions.

Definition edit

Global templates are special, which can be run on any Wikipedia. Global templates achieve the simplicity of calling templates, but at the same time the performance of programming languages.

Calls edit

Global templates always start with an underscore. A global call has a lower priority than a local one – it can be overridden.

Parameters edit

Parameters can be defined in 2 ways:

  • by default as call template in the present,
  • in the format of global templates.

Parameters are always sent as text from the forend.

Global templates (format) edit

Calling is similar to the C like programming language. Ie: key=value.

The basic types are:

  • variable (a=2024),
  • array (a=[2023,2024]),
  • object (a={before=2023, now=2024}).

Example edit

Call example edit

In the wiki syntax:

{{_sucet_2_parameters|5|3}}

Call definition edit

In the special section of the all global call definitions:

name=addition_2_parameters
parameter_1=string
parameter_2=string

Implementations edit

Implementation (C) edit

The parameters in the front end are not before-processed in any way, so the implementation has to process them by itself.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

char *addition_2_parameters(
	char *number1, uint16_t length1,
	char *number2, uint16_t length2
)
{
	long long int n1, n2, suma;
	char buffer[100];
	char *output;
	
	if(sscanf(number1, "%lld", &n1) != 1)
		return NULL;
	if(sscanf(number2, "%lld", &n2) != 1)
		return NULL;
		
	suma=n1+n2;
	
	snprintf(buffer, 100, "%lld", suma);
	
	output=strdup(buffer);
	
	return output;
}

#ifdef TEST
int main()
{
	char *result;
	
	// {{_addition_2_parameters|5|3}}
	result=addition_2_parameters(
		"5", 1,
		"3", 1
	);
	
	puts(result);
	
	free(result);
	
	return 0;
}
#endif

Implementation (C + glib) edit

The parameters in the front end are not before-processed in any way, so the implementation has to process them by itself.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <glib-2.0/glib.h>

GString *sucet_2_parameters(
	char *number1, uint16_t length1,
	char *number2, uint16_t length2
)
{
	long long int n1, n2, suma;
	GString *output;
	
	if(sscanf(number1, "%lld", &n1) != 1)
		return NULL;
	if(sscanf(number2, "%lld", &n2) != 1)
		return NULL;
	
	output=g_string_new(NULL);
	g_string_append_printf(output, "%lld", (long long int) (n1+n2));
	
	return output;
}

#ifdef TEST
int main()
{
	GString *result;
	
	// {{_sucet_2_parameters|5|3}}
	result=sucet_2_parameters(
		"5", 1,
		"3", 1
	);
	
	puts(result->str);
	
	g_string_free(result, TRUE);
	
	return 0;
}
#endif

Implementation (PHP) edit

The parameters in the front end are not before-processed in any way, so the implementation has to process them by itself.

<?php

function sucet_2_parameters(array $fargs) : string|bool
{
	if(!isset($fargs[0])) return false;
	if(!ctype_digit($fargs[0])) return false;
    
	if(!isset($fargs[1])) return false;
	if(!ctype_digit($fargs[1])) return false;
	
	return $fargs[0]+$fargs[1];
}

	
// {{_sucet_2_parameters|5|3}}
$result=sucet_2_parameters(array("5", "3"));

echo $result."\n";