From 5c31037fd741d0dfea71920df29fd82f787a992a Mon Sep 17 00:00:00 2001 From: Ulysse ARNAUD Date: Sat, 28 Oct 2023 23:25:35 +0200 Subject: [PATCH 1/5] Init github action check docker build Now on pull request only --- .github/workflows/check-docker-build.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/check-docker-build.yml diff --git a/.github/workflows/check-docker-build.yml b/.github/workflows/check-docker-build.yml new file mode 100644 index 000000000..22732c34e --- /dev/null +++ b/.github/workflows/check-docker-build.yml @@ -0,0 +1,13 @@ +name: Check Docker Build + +on: + pull_request: + +jobs: + check: + name: Check Docker Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Docker Compose Build + run: docker-compose build \ No newline at end of file From e5667140cdf48456ebdaeb30ee152264e06a649c Mon Sep 17 00:00:00 2001 From: Ulysse ARNAUD Date: Sun, 29 Oct 2023 11:37:32 +0100 Subject: [PATCH 2/5] Added powershell as new langage with classes as first concept --- web/thesauruses/meta_info.json | 1 + web/thesauruses/powershell/7/classes.json | 159 ++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 web/thesauruses/powershell/7/classes.json diff --git a/web/thesauruses/meta_info.json b/web/thesauruses/meta_info.json index d04d4cd99..da2b9b303 100644 --- a/web/thesauruses/meta_info.json +++ b/web/thesauruses/meta_info.json @@ -15,6 +15,7 @@ "objectivec": "Objective-C", "perl": "Perl", "php": "PHP", + "powershell": "PowerShell", "python": "Python", "r":"R", "ruby": "Ruby", diff --git a/web/thesauruses/powershell/7/classes.json b/web/thesauruses/powershell/7/classes.json new file mode 100644 index 000000000..e0e53d57e --- /dev/null +++ b/web/thesauruses/powershell/7/classes.json @@ -0,0 +1,159 @@ +{ + "meta": { + "language": "powershell", + "language_name": "Powershell", + "structure": "classes", + "language_version": "7" + }, + "concepts": { + "normal_class": { + "name": "Normal class", + "code": [ + "class ClassName {", + " # class body", + "}" + ] + }, + "abstract_class": { + "name": "Abstract class", + "not-implemented": true + }, + "interface": { + "name": "Interface", + "not-implemented": true + }, + "read_only_class": { + "name": "Read-only class", + "not-implemented": true + }, + "static_class": { + "name": "Static class", + "not-implemented": true + }, + "inner_class": { + "name": "Inner class", + "not-implemented": true + }, + "packages": { + "name": "Packages", + "code": [ + "using namespace Your.Package" + ] + }, + "class_with_generic_type": { + "name": "Class with a generic type", + "not-implemented": true + }, + "private_variables": { + "name": "Defining private variables", + "code": [ + "class ClassName {", + " hidden [string] $privateVariable = \"private\";", + "}" + ], + "comment": "It's not possible to define private variables in Powershell. The closest approximation is to define a hidden variable." + }, + "protected_variables": { + "name": "Defining protected variables", + "not-implemented": true + }, + "public_variables": { + "name": "Defining public variables", + "code": [ + "class ClassName {", + " [string] $publicVariable = \"public\";", + "}" + ] + }, + "static_variables": { + "name": "Defining static variables", + "code": [ + "class ClassName {", + " static [string] $staticVariable = \"static\";", + "}" + ] + }, + "private_functions": { + "name": "Defining private functions", + "code": [ + "class ClassName {", + " hidden [string] privateFunction() {", + " return \"private\";", + " }", + "}" + ], + "comment": "It's not possible to define private functions in Powershell. The closest approximation is to define a hidden function." + }, + "protected_functions": { + "name": "Defining protected functions", + "not-implemented": true + }, + "public_functions": { + "name": "Defining public functions", + "code": [ + "class ClassName {", + " [string] publicFunction() {", + " return \"public\";", + " }", + "}" + ] + }, + "static_functions": { + "name": "Defining static functions", + "code": [ + "class ClassName {", + " static [string] staticFunction() {", + " return \"static\";", + " }", + "}" + ] + }, + "extends_class": { + "name": "Class that inherits/extends another class", + "code": [ + "class ClassName : BaseClass {", + " # class body", + "}" + ] + }, + "extending_interface": { + "name": "Class/Interface that inherits/extends another class/interface", + "not-implemented": true + }, + "calling_superclass_functions": { + "name": "Calling a superclass function", + "code": [ + "" + ] + }, + "overriding_superclass_functions": { + "name": "Overriding a superclass function", + "not-implemented": true + }, + "instantiating_object": { + "name": "Instantiating a new object", + "code": [ + "$object = [ClassName]::new()", + "$object = New-Object ClassName" + ] + }, + "instantiating_polymorphic_object": { + "name": "Instantiating a polymorphic object", + "not-implemented": true + }, + "implement_constructor": { + "name": "Implementing a class constructor", + "code": [ + "class ClassName {", + " ClassName() {", + " # constructor body", + " }", + "}" + ] + }, + "implement_deconstructor": { + "name": "Implementing a class deconstructor", + "not-implemented": true + } + } +} \ No newline at end of file From 9d74e8a9d962cdcbdc3fd4c7c29a30102c5000d2 Mon Sep 17 00:00:00 2001 From: PentW0lf <31568025+PentW0lf@users.noreply.github.com> Date: Sun, 29 Oct 2023 22:58:58 +0530 Subject: [PATCH 3/5] Add files via upload --- web/thesauruses/lua/5/functions.json | 118 +++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 web/thesauruses/lua/5/functions.json diff --git a/web/thesauruses/lua/5/functions.json b/web/thesauruses/lua/5/functions.json new file mode 100644 index 000000000..5ae70a75b --- /dev/null +++ b/web/thesauruses/lua/5/functions.json @@ -0,0 +1,118 @@ +{ + "meta": { + "language": "lua", + "language_name": "Lua", + "structure": "functions", + "language_version": "5.1" + }, + "concepts": { + "void_function_no_parameters": { + "name": "Function that does not return a value and takes no parameters", + "code": [ + "function greet()\n\tprint(\"Hello, world!\")\nend\n\n-- Calling the function\ngreet()" + ] + }, + "void_function_with_parameters": { + "name": "Function that does not return a value and that takes 1 or more defined parameters", + "code": [ + "function addNumbers(a, b)\n\tlocal sum = a + b\n\treturn sum\nend\n\n-- Calling the function and storing the result in a variable\nlocal result = addNumbers(5, 3)\nprint(\"The sum is: \" .. result)" + ] + }, + "void_function_with_keyword_parameters": { + "name": "Function that does not return a value and that takes 0 or more defined keyword parameters", + "code": [ + "function myFunction(params)\n\tlocal param1 = params.param1 or \"default_value1\"\n\tlocal param2 = params.param2 or \"default_value2\"\n\tlocal param3 = params.param3 or \"default_value3\"\n\t-- Your code here, using param1, param2, param3\n\tprint(\"param1: \" .. param1)\n\tprint(\"param2: \" .. param2)\n\tprint(\"param3: \" .. param3)\nend\n\n-- Calling the function with keyword parameters\nmyFunction{\n\tparam1 = \"value1\",\n\tparam2 = \"value2\",\n}\nmyFunction{\n\tparam2 = \"value2\",\n\tparam3 = \"value3\",\n}\n\n-- OutPut:\nparam1: value1\nparam2: value2\nparam3: default_value3\nparam1: default_value1\nparam2: value2\nparam3: value3" + ], + "comment":"Lua doesn't have built-in support for named or keyword parameters like some other programming languages do, such as Python. However, you can emulate keyword parameters using a table (Lua's equivalent to dictionaries or maps) and passing named values within that table as above." + + }, + "void_function_variable_parameters": { + "name": "Function that does not return a value and function that takes an unknown number of parameters", + "code": [ + "function myFunction(...)\n\tlocal params = {...}\n\tfor i, v in ipairs(params) do\n\t\tprint(\"Parameter \" .. i .. \": \" .. v)\n\tend\nend\n\n-- Calling the function with different numbers of parameters\nmyFunction(1, 2, 3)\nmyFunction(\"apple\", \"banana\")\nmyFunction(\"cat\")\n\n--OutPut:\nParameter 1: 1\nParameter 2: 2\nParameter 3: 3\nParameter 1: apple\nParameter 2: banana\nParameter 1: cat" + ] + }, + "return_value_function_no_parameters": { + "name": "Function that returns a value and takes no parameters", + "code": [ + "function generateRandomNumber()\n\treturn math.random(1, 100)\nend\n\n-- Calling the function and storing the result in a variable\nlocal randomValue = generateRandomNumber()\nprint(\"Random number: \" .. randomValue)" + ] + }, + "return_value_function_with_parameters": { + "name": "Function that returns a value and takes 1 or more defined parameters", + "code": [ + "function addNumbers(a, b)\nlocal sum = a + b\nreturn sum\nend\n\n-- Calling the function and storing the result in a variable\nlocal result = addNumbers(5, 3)\nprint(\"The sum is: \" .. result)\n\n-- OutPut:\nThe sum is: 8" + ] + }, + "return_value_function_with_keyword_parameters": { + "name": "Function that returns a value and takes 0 or more defined keyword parameters", + "code": [ + "function myFunction(params)\n\t-- Access parameters using named fields\n\tlocal param1 = params.param1 or \"default_value1\"\n\tlocal param2 = params.param2 or \"default_value2\"\n\tlocal param3 = params.param3 or \"default_value3\"\n\n\t-- Perform some operations\n\tlocal result = param1 .. \", \" .. param2 .. \", \" .. param3\n\n\t-- Return the result\n\treturn result\nend\n\n-- Calling the function with a table containing named parameters\nlocal output1 = myFunction{\n\tparam1 = \"value1\",\n\tparam2 = \"value2\",}\n\nlocal output2 = myFunction{\n\tparam2 = \"value2\",\n\tparam3 = \"value3\",}\n\nprint(\"Output 1: \" .. output1)\nprint(\"Output 2: \" .. output2)\n\n--OutPut:\nOutput 1: value1, value2, default_value3\nOutput 2: default_value1, value2, value3" + ], + "comment":"In Lua, you can't use keyword parameters as you would in some other programming languages like Python. However, you can achieve a similar effect by passing a table with named fields as a single parameter to the function as above." + }, + "return_value_function_variable_parameters": { + "name": "Function that returns a value and takes an unknown number of parameters", + "code": [ + "function sum(...)\n\tlocal result = 0\n\n\tfor i, v in ipairs({...}) do\n\t\tresult = result + v\n\tend\n\n\treturn result\nend\n\n-- Calling the function with different numbers of parameters\nlocal result1 = sum(1, 2, 3)\nlocal result2 = sum(5, 10, 15, 20)\n\nprint(\"Result 1: \" .. result1)\nprint(\"Result 2: \" .. result2)\n\n--OutPut\nResult 1: 6\nResult 2: 50" + ] + }, + "anonymous_function_no_parameters": { + "name": "Anonymous function that takes no parameters", + "code": [ + "local myFunction = function()\n\tprint(\"Anonymous function with no parameters\")\nend\n\nmyFunction()\n--OutPut\n\nAnonymous function with no parameters" + ] + }, + "anonymous_function_with_parameters": { + "name": "Anonymous function that takes 1 or more defined parameters", + "code": [ + "local add = function(a, b)\n\treturn a + b\nend\n\nlocal result = add(5, 3)\nprint(\"The sum is: \" .. result)\n--OutPut:\nThe sum is: 8" + ] + }, + "anonymous_function_with_keyword_parameters": { + "name": "Anonymous function that takes 0 or more defined keyword parameters", + "code": [ + "local myFunction = function(params)\n\tlocal param1 = params.param1 or 'default_value1'\n\tlocal param2 = params.param2 or 'default_value2'\n\tlocal param3 = params.param3 or 'default_value3'\n\n\t-- Your code here, using param1, param2, param3\n\tprint('param1: ' .. param1)\n\tprint('param2: ' .. param2)\n\tprint('param3: ' .. param3)\nend\n\n-- Call the anonymous function with keyword parameters\nmyFunction{\n\tparam1 = 'value1',\n\tparam2 = 'value2',\n}\n\nmyFunction{\n\tparam2 = 'value2',\n\tparam3 = 'value3',\n}\n--OutPut\n\nparam1: value1\nparam2: value2\nparam3: default_value3\nparam1: default_value1\nparam2: value2\nparam3: value3" + ] + }, + "anonymous_function_variable_parameters": { + "name": "Anonymous function that takes an unknown number of parameters", + "code": [ + "local myFunction = function(params)\n\tlocal param1 = params.param1 or 'default_value1'\n\tlocal param2 = params.param2 or 'default_value2'\n\tlocal param3 = params.param3 or 'default_value3'\n\n\t-- Your code here, using param1, param2, param3\n\tprint('param1: ' .. param1)\n\tprint('param2: ' .. param2)\n\tprint('param3: ' .. param3)\nend\n\n-- Call the anonymous function with keyword parameters\nmyFunction{\n\tparam1 = 'value1',\n\tparam2 = 'value2',\n}\n\nmyFunction{\n\tparam2 = 'value2',\n\tparam3 = 'value3',\n}\n\n--OutPut:\nparam1: value1\nparam2: value2\nparam3: default_value3\nparam1: default_value1\nparam2: value2\nparam3: value3" + ], + "comment":"In Lua, anonymous functions (also known as closures or lambdas) typically do not natively support keyword parameters as in some other programming languages. However, you can achieve a similar effect by passing a table with named fields as a single argument to the anonymous function as above." + }, + "anonymous_function_no_parameters_with_return": { + "name": "Anonymous function that takes no parameters and returns a value", + "code": [ + "local myFunction = function()\n\treturn 'Hello from the anonymous function!'\nend\n\n-- Call the anonymous function and capture the result\nlocal result = myFunction()\n\n-- Print the result\nprint(result)\n\nOutPut:\nHello from the anonymous function!" + ] + }, + "anonymous_function_with_parameters_with_return": { + "name": "Anonymous function that takes 1 or more defined parameters and returns a value", + "code": [ + "local add = function(a, b)\n\treturn a + b\nend\n\n-- Call the anonymous function with parameters and capture the result\nlocal result = add(5, 3)\n\n-- Print the result\nprint('The sum is: ' .. result)\n\n--OutPut:\nThe sum is: 8" + ] + }, + "anonymous_function_with_keyword_parameters_with_return": { + "name": "Anonymous function that takes 0 or more defined keyword parameters and returns a value", + "code": [ + "local myFunction = function(params)\n\tlocal param1 = params.param1 or 'default_value1'\n\tlocal param2 = params.param2 or 'default_value2'\n\tlocal param3 = params.param3 or 'default_value3'\n\n\t-- Your code here, using param1, param2, param3\n\tlocal result = param1 .. ', ' .. param2 .. ', ' .. param3\n\n\t-- Return the result\n\treturn result\nend\n\n-- Call the anonymous function with keyword parameters and capture the result\nlocal output1 = myFunction{\n\tparam1 = 'value1',\n\tparam2 = 'value2',\n}\n\nlocal output2 = myFunction{\n\tparam2 = 'value2',\n\tparam3 = 'value3',\n}\n\n-- Print the results\nprint('Output 1: ' .. output1)\nprint('Output 2: ' .. output2)\n\n--OutPut:\nOutput 1: value1, value2, default_value3\nOutput 2: default_value1, value2, value3" + ] + }, + "anonymous_function_variable_parameters_with_return": { + "name": "Anonymous function that takes an unknown number of parameters and returns a value", + "code": [ + "local myFunction = function(...)\n\tlocal params = {...}\n\tlocal result = 'Parameters: '\n\n\tfor i, v in ipairs(params) do\n\t\tresult = result .. 'Parameter ' .. i .. ': ' .. v .. ' '\n\tend\n\n\treturn result\nend\n\n-- Call the anonymous function with different numbers of parameters and capture the result\nlocal result1 = myFunction(1, 2, 3)\nlocal result2 = myFunction('apple', 'banana')\nlocal result3 = myFunction('cat')\n\n-- Print the results\nprint(result1)\nprint(result2)\nprint(result3)\n\n--OutPut:\nParameters: Parameter 1: 1 Parameter 2: 2 Parameter 3: 3 \nParameters: Parameter 1: apple Parameter 2: banana \nParameters: Parameter 1: cat" + ] + }, + "call_subroutine": { + "name": "Call subroutine", + "not-implemented": "true" + }, + "return_from_subroutine": { + "name": "Return from subroutine", + "not-implemented": "true" + } + } +} \ No newline at end of file From e88de6252ed1f615edc6a50578deeac9b9697862 Mon Sep 17 00:00:00 2001 From: Ulysse ARNAUD <11415595+ulyssear@users.noreply.github.com> Date: Sun, 29 Oct 2023 20:27:59 +0100 Subject: [PATCH 4/5] Added not implemented for superclass function --- web/thesauruses/powershell/7/classes.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/web/thesauruses/powershell/7/classes.json b/web/thesauruses/powershell/7/classes.json index e0e53d57e..5ee3121ae 100644 --- a/web/thesauruses/powershell/7/classes.json +++ b/web/thesauruses/powershell/7/classes.json @@ -122,9 +122,7 @@ }, "calling_superclass_functions": { "name": "Calling a superclass function", - "code": [ - "" - ] + "not-implemented": true }, "overriding_superclass_functions": { "name": "Overriding a superclass function", @@ -156,4 +154,4 @@ "not-implemented": true } } -} \ No newline at end of file +} From 356e4b6cd4646a022030e91f16220fa962c40241 Mon Sep 17 00:00:00 2001 From: PentW0lf <31568025+PentW0lf@users.noreply.github.com> Date: Mon, 30 Oct 2023 02:02:54 +0530 Subject: [PATCH 5/5] Update functions.json --- web/thesauruses/lua/5/functions.json | 48 +++++++++++----------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/web/thesauruses/lua/5/functions.json b/web/thesauruses/lua/5/functions.json index 5ae70a75b..7bbabf3c5 100644 --- a/web/thesauruses/lua/5/functions.json +++ b/web/thesauruses/lua/5/functions.json @@ -9,101 +9,89 @@ "void_function_no_parameters": { "name": "Function that does not return a value and takes no parameters", "code": [ - "function greet()\n\tprint(\"Hello, world!\")\nend\n\n-- Calling the function\ngreet()" + "function greet()\nend" ] }, "void_function_with_parameters": { "name": "Function that does not return a value and that takes 1 or more defined parameters", "code": [ - "function addNumbers(a, b)\n\tlocal sum = a + b\n\treturn sum\nend\n\n-- Calling the function and storing the result in a variable\nlocal result = addNumbers(5, 3)\nprint(\"The sum is: \" .. result)" + "function addNumbers(a, b)\nend" ] }, "void_function_with_keyword_parameters": { "name": "Function that does not return a value and that takes 0 or more defined keyword parameters", - "code": [ - "function myFunction(params)\n\tlocal param1 = params.param1 or \"default_value1\"\n\tlocal param2 = params.param2 or \"default_value2\"\n\tlocal param3 = params.param3 or \"default_value3\"\n\t-- Your code here, using param1, param2, param3\n\tprint(\"param1: \" .. param1)\n\tprint(\"param2: \" .. param2)\n\tprint(\"param3: \" .. param3)\nend\n\n-- Calling the function with keyword parameters\nmyFunction{\n\tparam1 = \"value1\",\n\tparam2 = \"value2\",\n}\nmyFunction{\n\tparam2 = \"value2\",\n\tparam3 = \"value3\",\n}\n\n-- OutPut:\nparam1: value1\nparam2: value2\nparam3: default_value3\nparam1: default_value1\nparam2: value2\nparam3: value3" - ], - "comment":"Lua doesn't have built-in support for named or keyword parameters like some other programming languages do, such as Python. However, you can emulate keyword parameters using a table (Lua's equivalent to dictionaries or maps) and passing named values within that table as above." - + "not-implemented": "true" }, "void_function_variable_parameters": { "name": "Function that does not return a value and function that takes an unknown number of parameters", "code": [ - "function myFunction(...)\n\tlocal params = {...}\n\tfor i, v in ipairs(params) do\n\t\tprint(\"Parameter \" .. i .. \": \" .. v)\n\tend\nend\n\n-- Calling the function with different numbers of parameters\nmyFunction(1, 2, 3)\nmyFunction(\"apple\", \"banana\")\nmyFunction(\"cat\")\n\n--OutPut:\nParameter 1: 1\nParameter 2: 2\nParameter 3: 3\nParameter 1: apple\nParameter 2: banana\nParameter 1: cat" + "function myFunction(...)\nend" ] }, "return_value_function_no_parameters": { "name": "Function that returns a value and takes no parameters", "code": [ - "function generateRandomNumber()\n\treturn math.random(1, 100)\nend\n\n-- Calling the function and storing the result in a variable\nlocal randomValue = generateRandomNumber()\nprint(\"Random number: \" .. randomValue)" + "function generateRandomNumber()\nreturn true\nend" ] }, "return_value_function_with_parameters": { "name": "Function that returns a value and takes 1 or more defined parameters", "code": [ - "function addNumbers(a, b)\nlocal sum = a + b\nreturn sum\nend\n\n-- Calling the function and storing the result in a variable\nlocal result = addNumbers(5, 3)\nprint(\"The sum is: \" .. result)\n\n-- OutPut:\nThe sum is: 8" + "function addNumbers(a, b)\nreturn a,b\nend" ] }, "return_value_function_with_keyword_parameters": { "name": "Function that returns a value and takes 0 or more defined keyword parameters", - "code": [ - "function myFunction(params)\n\t-- Access parameters using named fields\n\tlocal param1 = params.param1 or \"default_value1\"\n\tlocal param2 = params.param2 or \"default_value2\"\n\tlocal param3 = params.param3 or \"default_value3\"\n\n\t-- Perform some operations\n\tlocal result = param1 .. \", \" .. param2 .. \", \" .. param3\n\n\t-- Return the result\n\treturn result\nend\n\n-- Calling the function with a table containing named parameters\nlocal output1 = myFunction{\n\tparam1 = \"value1\",\n\tparam2 = \"value2\",}\n\nlocal output2 = myFunction{\n\tparam2 = \"value2\",\n\tparam3 = \"value3\",}\n\nprint(\"Output 1: \" .. output1)\nprint(\"Output 2: \" .. output2)\n\n--OutPut:\nOutput 1: value1, value2, default_value3\nOutput 2: default_value1, value2, value3" - ], - "comment":"In Lua, you can't use keyword parameters as you would in some other programming languages like Python. However, you can achieve a similar effect by passing a table with named fields as a single parameter to the function as above." + "not-implemented": "true" }, "return_value_function_variable_parameters": { "name": "Function that returns a value and takes an unknown number of parameters", "code": [ - "function sum(...)\n\tlocal result = 0\n\n\tfor i, v in ipairs({...}) do\n\t\tresult = result + v\n\tend\n\n\treturn result\nend\n\n-- Calling the function with different numbers of parameters\nlocal result1 = sum(1, 2, 3)\nlocal result2 = sum(5, 10, 15, 20)\n\nprint(\"Result 1: \" .. result1)\nprint(\"Result 2: \" .. result2)\n\n--OutPut\nResult 1: 6\nResult 2: 50" + "function sum(...)\nreturn...\nend" ] }, "anonymous_function_no_parameters": { "name": "Anonymous function that takes no parameters", "code": [ - "local myFunction = function()\n\tprint(\"Anonymous function with no parameters\")\nend\n\nmyFunction()\n--OutPut\n\nAnonymous function with no parameters" + "local myFunction = function()\nend" ] }, "anonymous_function_with_parameters": { "name": "Anonymous function that takes 1 or more defined parameters", "code": [ - "local add = function(a, b)\n\treturn a + b\nend\n\nlocal result = add(5, 3)\nprint(\"The sum is: \" .. result)\n--OutPut:\nThe sum is: 8" + "local add = function(a, b)\nend" ] }, "anonymous_function_with_keyword_parameters": { "name": "Anonymous function that takes 0 or more defined keyword parameters", - "code": [ - "local myFunction = function(params)\n\tlocal param1 = params.param1 or 'default_value1'\n\tlocal param2 = params.param2 or 'default_value2'\n\tlocal param3 = params.param3 or 'default_value3'\n\n\t-- Your code here, using param1, param2, param3\n\tprint('param1: ' .. param1)\n\tprint('param2: ' .. param2)\n\tprint('param3: ' .. param3)\nend\n\n-- Call the anonymous function with keyword parameters\nmyFunction{\n\tparam1 = 'value1',\n\tparam2 = 'value2',\n}\n\nmyFunction{\n\tparam2 = 'value2',\n\tparam3 = 'value3',\n}\n--OutPut\n\nparam1: value1\nparam2: value2\nparam3: default_value3\nparam1: default_value1\nparam2: value2\nparam3: value3" - ] + "not-implemented": "true" }, "anonymous_function_variable_parameters": { "name": "Anonymous function that takes an unknown number of parameters", "code": [ - "local myFunction = function(params)\n\tlocal param1 = params.param1 or 'default_value1'\n\tlocal param2 = params.param2 or 'default_value2'\n\tlocal param3 = params.param3 or 'default_value3'\n\n\t-- Your code here, using param1, param2, param3\n\tprint('param1: ' .. param1)\n\tprint('param2: ' .. param2)\n\tprint('param3: ' .. param3)\nend\n\n-- Call the anonymous function with keyword parameters\nmyFunction{\n\tparam1 = 'value1',\n\tparam2 = 'value2',\n}\n\nmyFunction{\n\tparam2 = 'value2',\n\tparam3 = 'value3',\n}\n\n--OutPut:\nparam1: value1\nparam2: value2\nparam3: default_value3\nparam1: default_value1\nparam2: value2\nparam3: value3" - ], - "comment":"In Lua, anonymous functions (also known as closures or lambdas) typically do not natively support keyword parameters as in some other programming languages. However, you can achieve a similar effect by passing a table with named fields as a single argument to the anonymous function as above." + "local add = function(...)\nend" + ] }, "anonymous_function_no_parameters_with_return": { "name": "Anonymous function that takes no parameters and returns a value", "code": [ - "local myFunction = function()\n\treturn 'Hello from the anonymous function!'\nend\n\n-- Call the anonymous function and capture the result\nlocal result = myFunction()\n\n-- Print the result\nprint(result)\n\nOutPut:\nHello from the anonymous function!" + "local myFunction = function()\nreturn true\nend" ] }, "anonymous_function_with_parameters_with_return": { "name": "Anonymous function that takes 1 or more defined parameters and returns a value", "code": [ - "local add = function(a, b)\n\treturn a + b\nend\n\n-- Call the anonymous function with parameters and capture the result\nlocal result = add(5, 3)\n\n-- Print the result\nprint('The sum is: ' .. result)\n\n--OutPut:\nThe sum is: 8" + "local add = function(a, b)\nreturn a,b\nend" ] }, "anonymous_function_with_keyword_parameters_with_return": { "name": "Anonymous function that takes 0 or more defined keyword parameters and returns a value", - "code": [ - "local myFunction = function(params)\n\tlocal param1 = params.param1 or 'default_value1'\n\tlocal param2 = params.param2 or 'default_value2'\n\tlocal param3 = params.param3 or 'default_value3'\n\n\t-- Your code here, using param1, param2, param3\n\tlocal result = param1 .. ', ' .. param2 .. ', ' .. param3\n\n\t-- Return the result\n\treturn result\nend\n\n-- Call the anonymous function with keyword parameters and capture the result\nlocal output1 = myFunction{\n\tparam1 = 'value1',\n\tparam2 = 'value2',\n}\n\nlocal output2 = myFunction{\n\tparam2 = 'value2',\n\tparam3 = 'value3',\n}\n\n-- Print the results\nprint('Output 1: ' .. output1)\nprint('Output 2: ' .. output2)\n\n--OutPut:\nOutput 1: value1, value2, default_value3\nOutput 2: default_value1, value2, value3" - ] + "not-implemented": "true" }, "anonymous_function_variable_parameters_with_return": { "name": "Anonymous function that takes an unknown number of parameters and returns a value", "code": [ - "local myFunction = function(...)\n\tlocal params = {...}\n\tlocal result = 'Parameters: '\n\n\tfor i, v in ipairs(params) do\n\t\tresult = result .. 'Parameter ' .. i .. ': ' .. v .. ' '\n\tend\n\n\treturn result\nend\n\n-- Call the anonymous function with different numbers of parameters and capture the result\nlocal result1 = myFunction(1, 2, 3)\nlocal result2 = myFunction('apple', 'banana')\nlocal result3 = myFunction('cat')\n\n-- Print the results\nprint(result1)\nprint(result2)\nprint(result3)\n\n--OutPut:\nParameters: Parameter 1: 1 Parameter 2: 2 Parameter 3: 3 \nParameters: Parameter 1: apple Parameter 2: banana \nParameters: Parameter 1: cat" + "local myFunction = function(...)\nreturn...\nend" ] }, "call_subroutine": { @@ -115,4 +103,4 @@ "not-implemented": "true" } } -} \ No newline at end of file +}