Namespace a Lua gadget/AI

Namespace a Lua gadget/AI

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Petah
Posts: 426
Joined: 13 Jan 2008, 19:40

Namespace a Lua gadget/AI

Post 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?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Namespace a Lua gadget/AI

Post 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!
Post Reply

Return to “Lua Scripts”