Jump to content




Get code acces to local Vars


3 replies to this topic

#1 Wilma456

  • Members
  • 56 posts
  • LocationGermany

Posted 11 January 2017 - 04:34 PM

I want to code a plugin system and it need acces to the local vars of my programm. I had tried it with load(), but it don't have acces.

#2 Lupus590

  • Members
  • 1,507 posts
  • LocationUK

Posted 11 January 2017 - 05:43 PM

so you want your plugins to share the enviroment of your program?

I'm not 100% sure, but I think you can put everything into a table and use the table as the enviroment, how you do that I don't know.

#3 Sewbacca

  • Members
  • 386 posts
  • LocationStar Wars

Posted 11 January 2017 - 11:03 PM

Os.run() provides a similar possibility (No access to locals! It is just possible out of Lua or with the debug API to access them (CCTweaks support it)), you can put vars into a table and share it for your programs (They will be able to access _G). Otherwise you can create a table like os.run, with more possibilities (loadfile(setmetatable(path, {<Your vars>}, { __index = _G --[[To allow the program to use APIs]]})). If you are new at environments, i would recommend to look at the Lua manual. Sorry for so manny links. I am just in a link hype ^^.

#4 KingofGamesYami

  • Members
  • 2,574 posts
  • LocationUnited States of America

Posted 11 January 2017 - 11:13 PM

You can't do that. Even if you could, it would be a bad idea.

A better idea would be to pass the variables as arguments.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users