599 posts
Location
LeLua
Posted 22 September 2015 - 04:15 PM
Well this is the code that I have, but when I do:
tArgs={ ... }
It doesn't work…
My code:
local tEnv={ ..., window=win }
local _LG={}
for k, v in pairs(_G) do
_LG[k]=v
end
_LG.shell=nil
_LG.os=nil
_LG.term=nil
setmetatable( tEnv, {__index=_LG;} )
if func then
setfenv(func, tEnv)
win.func=func
win.co=coroutine.create(func)
else
return nil, err
end
1426 posts
Location
Does anyone put something serious here?
Posted 22 September 2015 - 04:21 PM
'Doesn't work' is rather vague, but I'll give it a go. You've got:
local tEnv={ ..., window=win }
If you swap the order, it should work:
local tEnv={ window=win, ... }
This is because if it is anything other than the first argument, only the first 'vararg' value will be used.
Edited on 22 September 2015 - 02:21 PM
599 posts
Location
LeLua
Posted 22 September 2015 - 04:23 PM
Nope, still crashes.
47 posts
Posted 22 September 2015 - 06:19 PM
When SquidDev said "'Doesn't work' is rather vague", I think they mean they'd like to see the error your getting. If you're not getting an error, describe what it's doing vs what it's supposed to do. They are correct that the table initializer should be written that way, if not you'll only get the first entry in the vararg table. If making that change didn't solve the problem, we're going to need more details as to what the problem is.
599 posts
Location
LeLua
Posted 22 September 2015 - 06:39 PM
Ok Im sleepy and I will do it in code:
Program file:
tArgs={ ... }
print(tArgs[1])
This is what I want.
570 posts
Posted 22 September 2015 - 07:14 PM
Ah, you're talking about program arguments I assume?
You need to put them into the
first coroutine.resume call:
coroutine.resume(win.co, "Hello World!")
That will make your program print "Hello World!"
Edited on 22 September 2015 - 05:15 PM
599 posts
Location
LeLua
Posted 22 September 2015 - 08:26 PM
Im talking about THE file, I know how coroutines work. Like shell.run. With args.
570 posts
Posted 22 September 2015 - 08:55 PM
Well, in that case, I'm afraid I don't know what you mean. Could you perhaps elaborate on what exactly you're trying to accomplish here and what exactly the problem is? "I'm doing this: (code), combined with this: (code) but it doesn't work." is extremely vague, making it only possible for us to guess what the code is supposed to do, leading to naught but misunderstandings. We will put roughly the same amount of effort into trying to solve your problem as you put into describing the problem, partially because that's just and fair, but also because it's very difficult to understand what the problem is in the first place.
So please, be more specific.
7083 posts
Location
Tasmania (AU)
Posted 23 September 2015 - 01:14 AM
… and saying something "doesn't work" is pointless. Say what it DOES do.
The code in your initial post is obviously incomplete. What value(s) does "…" represent? Where's "func" coming from, and where are the arguments you intend to "start" it with?
for k, v in pairs(_G) do
_LG[k]=v
end
Not entirely related to the-problem-you-can't-be-bothered-to-explain, but remember that _G is an element in _G. You'll hence want to ensure that _LG._G ends up pointing to _LG.
599 posts
Location
LeLua
Posted 23 September 2015 - 01:37 PM
Umm ok, I see… :D/> People huh? Ok… Last time, here we go: I don't have the fuction func is nil, _LG is not Local G table but instead a LG TV refference, oh what's …? Oh nothing just three dots that the sentence is not finnished or in Lua you can pass as many arguments as you can, oh and how does shell.run, os.run work, ikr no one knows, oh and yea did I talked about coroutines? Ofc not. And how theese words: "How to pass arguments? To a file or more specific function", being honest You just run your eyes over the thread and Oh I know, he wants to know how coroutines work. I didn't expect Forums be this… Mabie ill go to active live chats, I will get more help from there then from here. I'm done here… bye
1140 posts
Location
Kaunas, Lithuania
Posted 23 September 2015 - 02:14 PM
Just wanted to say that you seem pretty rude here. These people are trying to help you, even though you have given them very little information on what to help you with. If you want to get help, you first have to tell us what exactly is wrong, describe what is your end goal. I don't think you'll get help anywhere else, if you're not going to be a bit more specific.
130 posts
Posted 23 September 2015 - 02:43 PM
You're calling the function using coroutines so you need to pass the arguments using coroutines (setfenv has nothing to do with arguments) which is done by passing them to the first call to resume.
Example:
local co = coroutine.create(function(...)
-- this is how shell arguments work (though shell.run does some parsing)
local tArgs = {...}
print(tArgs[1])
end)
coroutine.resume(co, 'hello world')
--# prints 'hello world'
Also you can find out how shell.run and os.run work, edit rom/programs/shell, you can find the files in the ComputerCraft jar or look at
alekso56/ComputercraftLua (os.run is in bios.lua and shell.run is in rom/programs/shell).
599 posts
Location
LeLua
Posted 23 September 2015 - 02:45 PM
Ye forgot to add Thanks, but one thing: Coding is like competition to ne, I want to make a product sooo bad that I get angry.
47 posts
Posted 23 September 2015 - 03:22 PM
First of all, this is not how you post a thread. You provided us with very little information. You gave us an incomplete piece of code and no description of the error or malfunction you're having trouble with. You put practically no effort into your question, so in return we should provide practically no effort to help you. Instead, several users tried to help you anyway but, because of your vagueness, were unable to find your exact problem. Second, your reaction to these people trying to help you in spite of your vagueness is appalling. Your responses come off as rude and unappreciative towards people who are putting forth effort to help you beyond the effort you are willing to extend to them in asking for help. It's not their fault they can't solve your problem, it's your fault for not describing the problem well enough. If you really want our help, you have to act like it. If you want an answer to a question, you have to ask it in such a way that we understand what you want to know. Please provide us with the whole code and/or a proper description of the error or malfunction.
8543 posts
Posted 23 September 2015 - 07:46 PM
Please read the sticky posts, especially the one titled "Read This Post Before Asking Questions". Once you have thoroughly read and understood them, please take the time to form a proper question, one that we can actually answer. Your current post assumes that the reader has an in-depth knowledge of what you're trying to do. While it may seem obvious to you, that's the sort of thing you need to actually explain. Once you've posted a real question, don't then use all of your responses in the thread to make angry/sarcastic remarks at the people trying to help you just because they don't know what you're trying to do.
I rarely have to do this in Ask a Pro. Locked.