Jump to content




Script type API?


  • You cannot reply to this topic
14 replies to this topic

#1 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 21 July 2015 - 04: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 by LeDark Lua, 21 July 2015 - 04:32 PM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 21 July 2015 - 04:47 PM

I think you're looking for ..., like this:
local function foo( ... )
  local tArgs = {...}
  print( tArgs[ 1 ] )
end

foo( "Hello World" )


#3 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 21 July 2015 - 04: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 by LeDark Lua, 21 July 2015 - 04:52 PM.


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 21 July 2015 - 04:53 PM

local script = {}
script.init = function( ... )
  return function( ... ) print( ({...})[1] ) end
end

myScript = script.init()
myScript( "Hello World" )

?

#5 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 21 July 2015 - 04:54 PM

so now if i want to nest some code in there i just call: function myScript code here end ???

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 21 July 2015 - 04: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?

#7 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 21 July 2015 - 05:00 PM

No, im trying to make something so that I can run and pass arguments. I dont know if I explained that correctly...

#8 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 21 July 2015 - 05: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.

#9 flaghacker

  • Members
  • 655 posts

Posted 21 July 2015 - 05:04 PM

View PostLeDark Lua, on 21 July 2015 - 05:00 PM, said:

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 ;)

#10 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 21 July 2015 - 05: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 :|

#11 flaghacker

  • Members
  • 655 posts

Posted 21 July 2015 - 05: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 by flaghacker, 21 July 2015 - 05:13 PM.


#12 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 21 July 2015 - 05:15 PM

So ok, I want to run a file like so: myScript = script.init(path)
And then: myScript( ... )

#13 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 21 July 2015 - 05:23 PM

View PostMKlegoman357, on 21 July 2015 - 05:03 PM, said:

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.

View PostLeDark Lua, on 21 July 2015 - 05:15 PM, said:

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 ...?

#14 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 21 July 2015 - 05: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 by LeDark Lua, 21 July 2015 - 05:27 PM.


#15 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 21 July 2015 - 05: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")






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users