Modules Introduction: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "Modules are extensions for Multi Theft Auto's Lua core, allowing the integration and use of custom Lua functions that have been written in C++, and compiled as a DLL or SO file. Modules are commonly used to create functions for such purposes that Multi Theft Auto lacks, such as sockets. ==Getting sterted== To start writing new modules, you need to have at least basic knowledge of programming in C/C++.<br/> This tutorial '''does not teach''' you how t...")
 
mNo edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
Modules are extensions for Multi Theft Auto's Lua core, allowing the integration and use of custom Lua functions that have been written in C++, and compiled as a DLL or SO file. Modules are commonly used to create functions for such purposes that Multi Theft Auto lacks, such as [[Modules/Sockets|sockets]].
Modules are extensions for Multi Theft Auto's Lua core, allowing the integration and use of custom Lua functions that have been written in C++, and compiled as a DLL or SO file. Modules are commonly used to create functions for such purposes that Multi Theft Auto lacks, such as [[Modules/Sockets|sockets]].


==Getting sterted==
==Getting started==
To start writing new modules, you need to have at least basic knowledge of programming in C/C++.<br/>
To start writing new modules, you need to have at least basic knowledge of programming in C/C++.<br/>
This tutorial '''does not teach''' you how to get started with C++. <br/>
This tutorial '''does not teach''' you how to get started with C++. <br/>
Line 10: Line 10:
Make sure you have the [https://git-scm.com/downloads GIT] source control package installed.
Make sure you have the [https://git-scm.com/downloads GIT] source control package installed.
Open the command prompt (Win + R -> CMD) and enter this command:
Open the command prompt (Win + R -> CMD) and enter this command:
<p style="background-color:#141821;color:#fff;font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;padding:1%">
<pre<includeonly/>>
<span style = "color: yellow"> git </span> clone https://github.com/TracerDS/mtasa-modules.git
<span style="color:yellow">git</span> clone https://github.com/TracerDS/mtasa-modules.git
</p>
</pre>


===From website===
===From website===
Go to the website [https://github.com/TracerDS/mtasa-modules of the sample module] and download it (Green button "Code" -> "Download ZIP") then unpack the archive
Go to the website [https://github.com/TracerDS/mtasa-modules of the sample module] and download it (Green button "Code" -> "Download ZIP") then unpack the archive


<!--
== How do I start? ==
== How do I start? ==
Go to the <pre>./mtasa-modules/ml_example</pre> folder
Go to the <pre>./mtasa-modules/ml_example</pre> folder
Line 28: Line 29:


After running the script, a new folder should be created called '''myModule_module'''.
After running the script, a new folder should be created called '''myModule_module'''.
A Visual Studio project and a README file that you <span style = "color: red">'''MUST read'''</span> will be created in the current folder.
A Visual Studio project and a README file that you <span style="color:red">'''MUST read'''</span> will be created in the current folder.
-->
==Template's content==
===The structure of the template module===
*<span style="color:#177eff">'''hpp'''</span>
**<span style="color:#16c80c">config.hpp</span>
**<span style="color:#16c80c">functions.hpp</span>
**<span style="color:#16c80c;background-color:#880000">main.hpp</span>
*<span style="color:#177eff;background-color:#880000">'''include'''</span>
**<span style="color:#177eff;background-color:#880000">'''lua'''</span>
***<span style="color:#16c80c;background-color:#880000">lauxlib.h</span>
***<span style="color:#16c80c;background-color:#880000">lua.h</span>
***<span style="color:#16c80c;background-color:#880000">lua.hpp</span>
***<span style="color:#16c80c;background-color:#880000">luaconf.h</span>
***<span style="color:#16c80c;background-color:#880000">lualib.h</span>
**<span style="color:#177eff;background-color:#880000">'''mta'''</span>
***<span style="color:#16c80c;background-color:#880000">CLuaArgument.hpp</span>
***<span style="color:#16c80c;background-color:#880000">CLuaArguments.hpp</span>
***<span style="color:#16c80c;background-color:#880000">ILuaModuleManager.hpp</span>
***<span style="color:#16c80c;background-color:#880000">init.hpp</span>
***<span style="color:#16c80c;background-color:#880000">mta_main.hpp</span>
*<span style="color:#177eff;background-color:#880000">'''lib'''</span>
**<span style="color:#16c80c;background-color:#880000">'''lua5.1.lib'''</span>
**<span style="color:#16c80c;background-color:#880000">'''lua5.1_64.lib'''</span>
*<span style="color:#177eff">'''src'''</span>
**<span style="color:#177eff;background-color:#880000">'''mta'''</span>
***<span style="color:#16c80c;background-color:#880000">CLuaArgument.cpp</span>
***<span style="color:#16c80c;background-color:#880000">CLuaArguments.cpp</span>
***<span style="color:#16c80c;background-color:#880000">mta_main.cpp</span>
**<span style="color:#16c80c">functions.cpp</span>
**<span style="color:#16c80c">main.cpp</span>
*<span style="color:#16c80c">ml_basic.sln</span>
*<span style="color:#16c80c">ml_basic.vcxproj</span>
*<span style="color:#16c80c">ml_basic.vcxproj.filters</span>
*<span style="color:#16c80c">ml_basic.vcxproj.user</span>


==Template's content==
<ul><h3>The structure of the template module</h3>
<li><span style="color:#177eff">'''include'''</span></li><ul>
<!----><li><span style="color:#177eff;background-color:#880000">'''init'''</span><ul>
<!------><li><span style="color:#16c80c;background-color:#880000">Common.h</span></li>
<!------><li><span style="color:#16c80c;background-color:#880000">ILuaModuleManager.h</span></li>
<!------><li><span style="color:#16c80c;background-color:#880000">lauxlib.h</span></li>
<!------><li><span style="color:#16c80c;background-color:#880000">luaconf.h</span></li>
<!------><li><span style="color:#16c80c;background-color:#880000">lua.h</span></li>
<!------><li><span style="color:#16c80c;background-color:#880000">lua.hpp</span></li>
<!------><li><span style="color:#16c80c;background-color:#880000">lualib.h</span></li>
<!----></ul></li>
<!----><li><span style="color:#16c80c">CFunctions.h</span></li>
<!----><li><span style="color:#16c80c;background-color:#880000">CLuaArgument.h</span></li>
<!----><li><span style="color:#16c80c;background-color:#880000">CLuaArguments.h</span></li>
<!----><li><span style="color:#16c80c">ml_moduleName.hpp</span></li></ul>
<li><span style="color:#177eff;background-color:#880000">'''lib'''</span><ul>
<!----><li><span style="color:#16c80c;background-color:#880000">lua5.1.lib</span></li>
<!----><li><span style="color:#16c80c;background-color:#880000">lua5.1_64.lib</span></li></ul>
<li><span style="color:#177eff">'''src'''</span></li><ul>
<!----><li><span style="color:#16c80c">CFunctions.cpp</span></li>
<!----><li><span style="color:#16c80c;background-color:#880000">CLuaArgument.cpp</span></li>
<!----><li><span style="color:#16c80c;background-color:#880000">CLuaArguments.cpp</span></li>
<!----><li><span style="color:#16c80c">ml_example.cpp</span></li></ul>
<li><span style="color:#16c80c">ml_moduleName.sln</span></li>
<li><span style="color:#16c80c">ml_moduleName.vcxproj</span></li>
<li><span style="color:#16c80c">ml_moduleName.vcxproj.filters</span></li>
<li><span style="color:#16c80c">ml_moduleName.vcxproj.user</span></li>
<li><span style="color:#16c80c">README</span></li>
</ul>
<hr/>
<hr/>


Files are marked in <span style="color:#16c80c">green font</span><br/>
Files are marked in <span style="color:#16c80c">green font</span><br/>
Folders are marked in <span style="color:#177eff">bolded blue font</span><br/>
Folders are marked in <span style="color:#177eff">'''bolded blue font'''</span><br/>
<span style="color:#16c80c;background-color:#880000">Files</span> and <span style="color:# 177eff;background-color:#880000">folders</span> that '''should not''' be modified are marked in <span style="background-color:#880000">red</span>
<span style="color:#16c80c;background-color:#880000">Files</span> and <span style="color:#177eff;background-color:#880000">'''folders'''</span>
 
that '''should not''' be modified are marked in <span style="background-color:#880000">red</span>
==What is ___?==
'''Q:''' Folder '''init'''?<br/>
'''A:''' Dont touch this folder. The headers needed for initial module initialization are stored there.
 
'''Q:''' File '''CFunctions.h'''?<br/>
'''A:''' The declarations of user-created functions are stored there.
The definitions of these functions are stored in the file '''CFunctions.cpp'''.
 
'''Q:''' Folder '''lib'''?<br/>
'''A:''' Do not touch it at all. It stores the libraries needed for the connection between C++ and Lua.
 
'''Q:''' Files '''CLuaArgument/s.h/.cpp'''?<br/>
'''A:''' These files are used to correctly handle parameters from C++ to Lua


<!--
<!--
<span style="font-weight:bold;font-size:large">[[Modules_Introduction_2|Part 2]]</span>
<span style="font-weight:bold;font-size:large">[[Modules_Introduction_2|Part 2]]</span>
-->
-->
[[pl:Modules Introduction]]

Latest revision as of 17:06, 23 May 2023

Modules are extensions for Multi Theft Auto's Lua core, allowing the integration and use of custom Lua functions that have been written in C++, and compiled as a DLL or SO file. Modules are commonly used to create functions for such purposes that Multi Theft Auto lacks, such as sockets.

Getting started

To start writing new modules, you need to have at least basic knowledge of programming in C/C++.
This tutorial does not teach you how to get started with C++.
Let's start by downloading a template to create our own module. We can do it in 2 ways:

From terminal

Make sure you have the GIT source control package installed. Open the command prompt (Win + R -> CMD) and enter this command:

git clone https://github.com/TracerDS/mtasa-modules.git

From website

Go to the website of the sample module and download it (Green button "Code" -> "Download ZIP") then unpack the archive

Template's content

The structure of the template module

  • hpp
    • config.hpp
    • functions.hpp
    • main.hpp
  • include
    • lua
      • lauxlib.h
      • lua.h
      • lua.hpp
      • luaconf.h
      • lualib.h
    • mta
      • CLuaArgument.hpp
      • CLuaArguments.hpp
      • ILuaModuleManager.hpp
      • init.hpp
      • mta_main.hpp
  • lib
    • lua5.1.lib
    • lua5.1_64.lib
  • src
    • mta
      • CLuaArgument.cpp
      • CLuaArguments.cpp
      • mta_main.cpp
    • functions.cpp
    • main.cpp
  • ml_basic.sln
  • ml_basic.vcxproj
  • ml_basic.vcxproj.filters
  • ml_basic.vcxproj.user

Files are marked in green font
Folders are marked in bolded blue font
Files and folders that should not be modified are marked in red