func helloWorld( $str="Hello world" ) print $str end helloWorld() --Output: Hello world helloWorld "Hello, world!" --Output: Hello, world!
Thanks in advance.
LeDark Lua
Edited by LeDark Lua, 28 August 2015 - 11:15 AM.
Posted 28 August 2015 - 11:14 AM
func helloWorld( $str="Hello world" ) print $str end helloWorld() --Output: Hello world helloWorld "Hello, world!" --Output: Hello, world!
Edited by LeDark Lua, 28 August 2015 - 11:15 AM.
Posted 28 August 2015 - 11:28 AM
Posted 28 August 2015 - 11:30 AM
Edited by LeDark Lua, 28 August 2015 - 11:31 AM.
Posted 28 August 2015 - 12:56 PM
Posted 28 August 2015 - 01:44 PM
Posted 28 August 2015 - 03:02 PM
local y = 1
local function a( x ) --> x is local to this function
print( x ) --> looks for 'x' in top scope (function scope), finds it, so x is refering to 'x' of the function scope
print( y ) --> looks for 'y' in the top scope (function scope), doesn't find it, so looks for it as an upvalue (and finds it)
end
Posted 28 August 2015 - 03:13 PM
func a( $x="test" ) print( x ) end a "Hi" --[[VM does this: x = "a:var x= string hi" --]]
Posted 28 August 2015 - 03:53 PM
Posted 28 August 2015 - 05:07 PM
functions={}
Then when I assign it:function addFunc(funcName, code) functions[funcName]=code endIf I want to run it:
function runFunc(funcName) parse(functions[funcName]) end
Edited by LeDark Lua, 28 August 2015 - 05:09 PM.
Posted 28 August 2015 - 05:21 PM
Posted 28 August 2015 - 05:40 PM
func do($test="default") print $test end --This would print the "default" only because I dont know how to pass that "weird stuff." string. do "weird stuff."
Edited by LeDark Lua, 28 August 2015 - 05:42 PM.
Posted 28 August 2015 - 05:43 PM
Posted 28 August 2015 - 05:44 PM
Posted 28 August 2015 - 06:35 PM
Posted 29 August 2015 - 10:07 AM
addFunc("HelloWorld", function()
print("Hello, world!")
end)
function addFunc(funcName, tokens, scope)
functions[funcName]=tokens
if scope then
local i=1
while i<=#scope do
local sc=scope[i+2]
if sc:sub(1, 3)=="NUM" then
doASSIGN(scope[i], sc:sub(5))
i=i+3
elseif sc:sub(1, 6)=="STRING" then
doASSIGN(scope[i], sc:sub(9))
i=i+3
elseif sc:sub(1, 4)=="EXPR" then
doASSIGN(scope[i], sc:sub(6))
i=i+3
elseif sc:sub(1, 3)=="VAR" then
doASSIGN(scope[i], getVARIABLE(sc))
i=i+3
end
end
functionScopes[funcName]=scope
else
functionScopes[funcName]={}
end
end
local function runFunc(funcName)
if functions[funcName] then
if type(functions[funcName])=="table" then
parseFunc(functions[funcName], functionScopes[funcName])
elseif type(functions[funcName])=="function" then
if #functionScopes[funcName]<1 then
functions[funcName]()
end
end
if functionScopes[funcName] then
for k, _ in pairs(functionScopes[funcName]) do
symbols[k]=nil
end
end
else
printError("Can't run a non existant function.")
end
end
Edited by LeDark Lua, 29 August 2015 - 10:09 AM.
Posted 29 August 2015 - 01:48 PM
$number = 15 $helloWorld = "Hello, world!" if $number == 15 then :print $helloWorld "Works!" : endif :print "No commas ',' WOOHOO!" :
addFunc("print", function(input)
local __str = ""
for i=1, #input do
__str = __str..input[i].." "
end
print(__str)
end)
Edited by LeDark Lua, 29 August 2015 - 01:55 PM.
Posted 29 August 2015 - 04:24 PM
0 members, 2 guests, 0 anonymous users