Difference between revisions of "Embedding Lua in the Source Engine:ru"

From Valve Developer Community
Jump to: navigation, search
(Created page with "{{otherlang2 |title= Внедрение Lua в Source |en=Embedding_Lua_in_the_Source_Engine }} {{orphan}}{{pov}} <div style="margin:auto;text-align:center;"> '''User:Andr...")
Line 11: Line 11:
== Что такое Lua? ==
== Что такое Lua? ==

Revision as of 06:56, 24 May 2019


Andrew C. P. McWatters ([email protected]), 2010
Software Development Engineer



Что такое Lua?

Lua это мощный, быстрый, легкий, встраиваемый скриптовый язык.

Lua сочетает в себе простой процедурный синтаксис с мощными конструкциями описания данных на основе ассоциативных массивов и расширяемой семантики. Lua динамически типизируется, выполняется путем интерпретации байт-кода для виртуальной машины на основе регистра и имеет автоматическое управление памятью с инкрементной сборкой мусора, что делает его идеальным для конфигурации, сценариев и быстрого прототипирования.

Вы можете узнать больше о Lua на официальном сайте.


Lua is currently the leading scripting language in games, and for Steam users, is synonymous with Garry's Mod. Unfortunately, Garry's Mod isn't open source, and as a result, we cannot use Team Garry's implementation of Lua for our and others' benefit. However, my project, <Half-Life 2> Half-Life 2: Sandbox is currently the leading open source project dedicated to bringing the developer community a method for embedding Lua into their mod nearly seamlessly, and in this article I'll explain how.

Half-Life 2: Sandbox uses a pure variant of Lua, different than Garry's implementation of the language, which has restrictions on many libraries, and modified syntax for C++ styled comments. Half-Life 2: Sandbox's goal is to provide a neutral, clean, standardized and well documented code base for interfacing with Lua, unlike articles seen within the Valve Developer Community such as the LuaBind oriented Lua tutorial or Adding Lua article.




The Lua manager scripts found in the Half-Life 2: Sandbox source code were written generically so they could be added to any mod.

  • If you're working with a mod's source code, rather than a plugin, the files above should be placed within src/game/shared
  • In your project files, place both the luamanager.cpp and luamanager.h in the Source Files filter
  • Compile your binaries
  • Simply add the precompiled lua51.dll to your mod's bin folder, and now your mod has integrated Lua!

Update: Half-Life 2: Sandbox has went through several revisions extending its Lua API greatly including many classes and libraries for real-world usage with Source. As a result of these expansions, you'll now find that to be able to use these classes, you'll need to add the individual class .cpp and .h files, which are all listed in luamanager.cpp by headers that correspond to .cpp files.

External links