Depends on how you want to add it. It could be as simple as if available cast on self or you could make it more advanced for example, if mana below 40% and/or health below 40%.
As far as the programming part, in lua you must have at least one condition, then at least one reaction, and a stopping point. Advanced functions only come after you learn the basic syntax
The easiest thing I can tell you about beginning lua programming is start in laymens terms.
After you get this far its simply finding the syntax to set your conditions then your reactions and then your end. After a while you can completely skip this step, but getting in the habit of thinking out what you want and when you want it will help you make sure the syntax is correct.What to cast - Incanter's ward
When to cast - at 40% health and/or 40% mana, or hero, or intelligence/haste/crit gain greater than 2000.
What are my conditions - A. 40% health B. 40% mana C. Hero D. Haste gain E. Intelligence gain F. Crit Gain
What is my reaction - cast incanter's ward if more than X conditions are met, x=numerical value, or if A is true.