public static void addFunction(SiddhiAppContext siddhiAppContext,
                                   final FunctionDefinition functionDefinition) {

        Extension extension = new Extension() {
            @Override
            public String getNamespace() {
                return "script";
            }

            @Override
            public String getName() {
                return functionDefinition.getLanguage().toLowerCase();
            }
        };
        try {
            Script script = (Script) SiddhiClassLoader.loadExtensionImplementation(extension,
                    ScriptExtensionHolder.getInstance(siddhiAppContext));
            ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager()
                    .generateConfigReader(extension.getNamespace(), extension.getName());
            script.setReturnType(functionDefinition.getReturnType());
            script.init(functionDefinition.getId(), functionDefinition.getBody(), configReader);
            siddhiAppContext.getScriptFunctionMap().put(functionDefinition.getId(), script);
        } catch (Throwable t) {
            ExceptionUtil.populateQueryContext(t, functionDefinition, siddhiAppContext);
            throw t;
        }
    }
Utility class for queryParser to help with QueryRuntime
generation.
modules/siddhi-core/src/main/java/io/siddhi/core/util/parser/helper/DefinitionParserHelper.java