Page 1 of 1

Namespace a Lua gadget/AI

Posted: 06 Sep 2013, 11:13
by Petah
How would I namespace a Lua AI, and separate it into separate files?

I am making an AI with lots of functions. To be maintainable it needs to be separated into different files based. How would I do this?

Also how would I namespace these functions so they do not conflict with other functions?

Re: Namespace a Lua gadget/AI

Posted: 06 Sep 2013, 18:22
by FLOZi

Re: Namespace a Lua gadget/AI

Posted: 06 Sep 2013, 21:12
by zwzsg
You put all your public functions and variables into a table.
You make the "library" lua file return that table.
You make the "parent" lua file put the result of the include into a table.

Then, instead of local names in a namespace, you use named fields of your table. If all your methods have self as their first argument, you can even use the : almost like in C namespaces!