OOP in Lua: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 14: Line 14:
== Initialising ==
== Initialising ==
There is a basic and simple predefined variables we should recognize and know: '''self'''. Which refers to the environment within which we are executing a code.
There is a basic and simple predefined variables we should recognize and know: '''self'''. Which refers to the environment within which we are executing a code.
=== Our first environment ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
self --
local environment = {}
function environment:example (argument)
return "Hello"
end
</syntaxhighlight>
</syntaxhighlight>
What we do upon above is defining a ''local'' environment and then declaring the function '''example''' as part of it.

Revision as of 01:38, 18 January 2015

This content is not concluded yet.


This template is no longer in use as it results in poor readability.

This is a scripting tutorial that teaches you how to start using an Object-Oriented developing interface with Lua.

Glossary

  • environment: either a table or an array containing values.

Initialising

There is a basic and simple predefined variables we should recognize and know: self. Which refers to the environment within which we are executing a code.

Our first environment

local environment = {}
function environment:example (argument)
	return "Hello"
end

What we do upon above is defining a local environment and then declaring the function example as part of it.