599 posts
Location
LeLua
Posted 21 July 2015 - 05:29 PM
Well I explained it wrong mabie but ill give it a shot. This is what I have in mind:
I initialize a script like so:
myScript=script.init()
Then i can run it with arguments if there is like: myName=argument[1]
and then:
myScript("LeDarkLua")
and that script has:
myName=argument[1]
print(myName)
Thanks in advance!
Edited on 21 July 2015 - 03:32 PM
3057 posts
Location
United States of America
Posted 21 July 2015 - 05:47 PM
I think you're looking for …, like this:
local function foo( ... )
local tArgs = {...}
print( tArgs[ 1 ] )
end
foo( "Hello World" )
599 posts
Location
LeLua
Posted 21 July 2015 - 05:49 PM
yeah something like that, but just how to establish it or create this. Like I said in the thread?
Someone did a class system like java and they did something like: class "name" { } or something like that.
Edited on 21 July 2015 - 03:52 PM
3057 posts
Location
United States of America
Posted 21 July 2015 - 05:53 PM
local script = {}
script.init = function( ... )
return function( ... ) print( ({...})[1] ) end
end
myScript = script.init()
myScript( "Hello World" )
?
599 posts
Location
LeLua
Posted 21 July 2015 - 05:54 PM
so now if i want to nest some code in there i just call: function myScript code here end ???
3057 posts
Location
United States of America
Posted 21 July 2015 - 05:57 PM
Sorry, I'm not sure what you're trying to accomplish here.
What I did was make a function that returns another function. Which is pretty much pointless. Are you trying to make objects?
599 posts
Location
LeLua
Posted 21 July 2015 - 06:00 PM
No, im trying to make something so that I can run and pass arguments. I dont know if I explained that correctly…
1140 posts
Location
Kaunas, Lithuania
Posted 21 July 2015 - 06:03 PM
I think he's trying to do the 'user script' part of
this.
So the scripts would be placed in separate files? In this situation you'll either have to support Lua 5.1, Lua 5.2 or both. I'd suggest to support both. But note that CC is already started to slowly upgrade to Lua 5.2.
Anyway, this thing will need to work with
function environments. You'd basically load the file with the custom environment containing your custom variables.
656 posts
Posted 21 July 2015 - 06:04 PM
No, im trying to make something so that I can run and pass arguments. I dont know if I explained that correctly…
You're describing a simple function there, maybe try again ;)/>
599 posts
Location
LeLua
Posted 21 July 2015 - 06:06 PM
Ok then :D/>, well its like a function but a bit simplier or something. Well look at GameMaker making scripts and you will see what I mean. Im baaaad at explaining :|
656 posts
Posted 21 July 2015 - 06:13 PM
I never actually used Gamemaker, so I read
this page, and I get the feeling scripts and functions are the same thing: they have a name, they get arguments, they run code and they return stuff. Am I failing to see something here? Could you perhaps try to explain the diffrence between scripts and functions?
Edited on 21 July 2015 - 04:13 PM
599 posts
Location
LeLua
Posted 21 July 2015 - 06:15 PM
So ok, I want to run a file like so: myScript = script.init(path)
And then: myScript( … )
1140 posts
Location
Kaunas, Lithuania
Posted 21 July 2015 - 06:23 PM
I think he's trying to do the 'user script' part of
this.
So the scripts would be placed in separate files? In this situation you'll either have to support Lua 5.1, Lua 5.2 or both. I'd suggest to support both. But note that CC is already started to slowly upgrade to Lua 5.2.
Anyway, this thing will need to work with
function environments. You'd basically load the file with the custom environment containing your custom variables.
So ok, I want to run a file like so: myScript = script.init(path)
And then: myScript( … )
And …? You don't know …? You cannot figure a way to do …?
599 posts
Location
LeLua
Posted 21 July 2015 - 06:27 PM
coroutines and loadstring…. or shell.run or os.run :D/>
Lemme introduce myself: Im a dummy and I can sometimes ask dumb questions.
Edited on 21 July 2015 - 04:27 PM
599 posts
Location
LeLua
Posted 21 July 2015 - 06:37 PM
Ok i got it…. Im so dumb, sorry 'bout this
local function scriptAdd( ... )
return function( ... ) os.run({ argument={ ... } }, "/test") end
end
myScript = scriptAdd()
myScript("LeDarkLua")