Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Lua Script Template Engine ("compiled templates")

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions
View previous topic :: View next topic  
Author Message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Tue Dec 21, 2021 7:24 pm    Post subject: Lua Script Template Engine ("compiled templates") Reply with quote

Lua Script Template Engine ("compiled templates")

For Auto Assembler Templates see this post.

This is a Lua script template engine that compiles/renders templates, the template engine is based off this blog post. You can access variables and run lua code in the templates using the appropriate tags. There are two file's you'll need to start; "TemplateEngine.lua" and "LuaScriptTemplates.lua". You can just stick them both in the "autorun" folder. And you'll need to create the "Templates\lua" Folder (in the "autorun" folder) for the templates.

When CE loads, "LuaScriptTemplates" will scan the templates folder for "LoadOrder.lua" if found and it returns a table/array of file names it will load in that order; if not found is will scan the templates folder for any ".lua" files. When it finds a template file it will also look for "[template file name].settings.lua", the settings file is not required but allows for more control of the template and menu items added to the Lua script form. The settings file can return a table of the template's settings, but this is not required (more on why later).

For simple output you can use "<<" and ">>" tags, what ever is returned will be converted to string if not already and replace where the open and close tags are; these can be a called function, variable, or just a string/number. For lua code you can use "<%" and "%>" tags, these can be full lua code; thus you can set/create variables, use loops, and if statements.

For an archive with the needed files and one example template and setting file see this post else you can download the main files below.

Using a template file named "My basic template.lua" like this:
Code:
-- Cheat Engine Version: << getCEVersion() >>
<% print('This will print when rendered but will not render in the template.') %>
<% local text = 'here is a local variable created in the template.' %>
<< text >> So that's pretty cool.
-- if you need "\<<" or "\<%" to be in the rendered template then you need to escape them.
-- A single "<" doesn't need to be escaped, nor do ">>" and "%>".
print('This is in the template and not processed when rendered.')


It will show up in the auto assembler form's template menu as "My basic template" and render like this:
Code:
-- Cheat Engine Version: 7.2

here is a local variable created in the template. So that's pretty cool.
-- if you need "<<" or "<%" to be in the rendered template then you need to escape them.
-- A single "<" doesn't need to be escaped, nor do ">>" and "%>".
print('This is in the template and not processed when rendered.')



There is another special file named "Header.lua" which is rendered then passed to the template as "Header":
Code:

<< Header >>
-- This allows for a common header without polluting the template file it self
-- and can have lua code like the template files.
-- But it will be a blank line if there's no header file.



For a settings file for "My basic template.lua" we can create a file named "My basic template.settings.lua" like this:
Code:
local settings = {
   Caption = 'Custom: Basic Template',
   Shortcut = 'Ctrl+Alt+1',
}
return settings


Template settings are listed here:
Code:
Template Settings:
   Caption : string
      The caption of the template's menu item.
   Shortcut : string
      The shortcut of the template's menu item.


The variables passed to the template, and settings file on final compilation, are listed here:
Code:
Template Variables:
   CEVersion : number
      The current CE version.
   Date : string
      The current date.
   FinalCompilation : boolean
      Only for the settings files as they get loaded once when CE loads then again at the start
      of template rendering to get the template settings, and again just before rendering the
      template but only on the last load will the environment be setup.
      So this is used to know if the environment is setup if more environment setup is done in
      the setting file.


Globals are accessible in the templates and settings files, but through a metatable thus they can not be set in a template or setting's file. But the environment variables can be manipulated in the settings file's directly during final compilation.

Any "globals" (not really globals and only exist in the template/settings environment) created in the settings file are passed to the template file.. You can use a settings file like this to add to the template's environment:
Code:
if FinalCompilation then
   TimerInterval = inputQuery('Timer Interval', 'Enter timer interval', '100')
   TimerMaxSecs = inputQuery('Timer Max. Seconds', 'Enter timer max. seconds', '300')
end


The template will get the new variables when rendered.



LuaScriptTemplates.lua
 Description:

Download
 Filename:  LuaScriptTemplates.lua
 Filesize:  4.64 KB
 Downloaded:  675 Time(s)


TemplateEngine.lua
 Description:

Download
 Filename:  TemplateEngine.lua
 Filesize:  3.89 KB
 Downloaded:  658 Time(s)


_________________
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites