477 posts
Location
Germany
Posted 16 November 2014 - 09:52 AM
Hi,
i have the following problem: I need a global table which is the same in an API and a normal Program(something like this:
API:
function addtotable(value)
table[#table + 1] = value
end
Normal program:
table = {}
os.loadAPI("/API")
API.addtotable("test")
print(table[1])
The output of this is nothing, but should be "test". I hope someone knows a solution.
8543 posts
Posted 16 November 2014 - 10:35 AM
Why? There are ways something like this could be done, but there's probably a better way to accomplish whatever you plan on using this for. What's the end goal?
477 posts
Location
Germany
Posted 16 November 2014 - 12:43 PM
I wanna save some coroutines in two tables: one for running coroutines, one for suspended, you should be able to use a function like multitasking.addtask(task), etc. but the loop, which resumes the coroutines is in another Program. Now the program with the loop and the multitasking API cant acces the same Table(The loop program cant find any coroutines running/suspended). Thats my Problem.
Edited on 16 November 2014 - 11:47 AM
1140 posts
Location
Kaunas, Lithuania
Posted 16 November 2014 - 01:13 PM
Then I would suggest making all of your multitasking system into one API/program.
477 posts
Location
Germany
Posted 16 November 2014 - 01:41 PM
I tried it, but if I put the while loop into the API no more code will be executed after os.loadAPI()
1140 posts
Location
Kaunas, Lithuania
Posted 16 November 2014 - 02:58 PM
Well, you can make a function in the API which would hold your main loop:
function main ()
while true do
--// code here
end
end
477 posts
Location
Germany
Posted 16 November 2014 - 05:37 PM
That would be an idea, i will try this
EDIT: Tried it, but it only runs the coroutine ones…
Btw, why cant you use tables in an API and a program at once?
I have another idea too now, i will execute the API as an program. I will test this now.
Edited on 16 November 2014 - 04:51 PM
3057 posts
Location
United States of America
Posted 16 November 2014 - 06:03 PM
You can define a table globally inside your api, and access it through api_name.table_name in your program.
However, what MKlegoman said should work, if you do it properly.
477 posts
Location
Germany
Posted 16 November 2014 - 08:07 PM
Thanks, i just tried to access the Table, now i know how to fix my Program :D/>. And thanks to anyone other who help!