Code Monkey home page Code Monkey logo

luapreprocessor's Introduction

Lua preprocessor

It's mainly made to be used with löve framework, but if you supply your own filesystem operation functions it can work with any Lua platform.

Quick Implementation

--Supply filesystem.read. Might return DataStringOrNil, ErrorString  to work
PreProcessor.ReplaceFileSystemReadFunction(love.filesystem.read)

local PreProcessor = require("PreProcessor")
PreProcessor.PrepareEnvironment(_G)

local GeneratedCode = PreProcessor.GenerateCode("MyFile.lua", _G)
local CompiledCode, Err = loadstring(GeneratedCode)

if CompiledCode then
	CompiledCode()
else
	error("Could not compile code. Error: " .. Err)
end

The code is based in SimpleLuaPreprocessor so it does share similar syntax when in use such as:

@for i = 1, 5 do
  print($(i))
@end

will compile to

print(1)
print(2)
print(3)
print(4)
print(5)

This preprocessor supports string and comments blocks, except for the $(code) syntax, it will work except inside comment blocks. Strings will be parsed as such. @line codes will be ignored in comments and string blocks.

There's a built in function for including files, use it

$(include("path.lua"))

Library Functions

--Supply your own filesystem.read function that returns DataStringOrNil, ErrorString to work on different platforms:
PreProcessor.ReplaceFileSystemReadFunction(Func)
--Use the following function to copy useful functions like include to your preprocessing environment:
PreProcessor.PrepareEnvironment(EnvironmentTable or _G)

--Use this function for preprocessing your code and returning it as a string, the path provided must contain the extension.
StringCode = PreProcessor.GenerateCode(Path, EnvironmentTable or _G)

luapreprocessor's People

Contributors

shell64 avatar

Stargazers

David Hayes avatar  avatar István Bozsó avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.