func helloWorld( $str="Hello world" )
print $str
end
helloWorld()
--Output: Hello world
helloWorld "Hello, world!"
--Output: Hello, world!
Thanks in advance.
LeDark Lua
func helloWorld( $str="Hello world" )
print $str
end
helloWorld()
--Output: Hello world
helloWorld "Hello, world!"
--Output: Hello, world!
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
func a( $x="test" )
print( x )
end
a "Hi"
--[[VM does this:
x = "a:var x= string hi"
--]]
functions={}
Then when I assign it:
function addFunc(funcName, code)
functions[funcName]=code
end
If I want to run it:
function runFunc(funcName)
parse(functions[funcName])
end
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."
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
$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)