Giter VIP home page Giter VIP logo

gklua's Introduction

GKLua

Warning

THIS DOES NOT COMPILE, DO NOT TRY

Lua Integration for Unreal Engine based on the Script Plugin by Epic. Updated to 5.0 with a few improvements

Requirements

  • UE5.0+

Development Install

Install the python package to run this example as a gym environment

git submodule add https://github.com/Delaunay/GKLua Plugins/GKLua

Usage

  1. Create a new lua file inside the your content folder
  2. When the editor is going to import the script it will ask you which class this script is inheriting from.
  3. When the content of the script is modified the script will be reimported by the editor
function BeginPlay()
   print("BeginPlay in lua" .. this.Get_ActorTransform())
end

function Tick(delta)
   print("Tick in lua")
end

function Destoy()
   print("End play in lua")
end

function MyCustomFunctionCallableInBlueprint()
   print("Callable")
end

Overview

Note

You need to launch the editor once for the plugin to generate the Lua wrapeprs

  • GKLuaEditor
    • "Compiles" the blueprint
      • Generate the blueprint class from a blueprint a sets up the calls
      • Code is loaded in FLuaContext::Initialize when luaL_loadstring(LuaState, TCHAR_TO_ANSI(*Code) is called
      • We can use lua_dump to retrive the compiled bytecode
      • bytecode can be loaded using lua_loadstring NOT luaL_loadstring which is currently used
    • Specialize the Blueprint Editor
  • GKLuaGenerator
    • Generates lua wrappers
    • Hooks into the UHT (Unreal Header Tools) to generate the wrappers
  • GKLua
    • Manage the lua VM
    • Register new libraries at runtime
    • Call Lua Functions
    • All objects that interacts with LUA get a lua_state
      • Lua can be hooked to Tick, Destoy, BeginPlay
    • You can use this in lua to access the current object being implemented by the script
    • Objects that use lua create a ScriptBlueprint which holds the lua script so lua is next to the blueprint system. Used to be able to specify a source file. seems deprecated which might mean the code is bundled in the .asset instead of being readable text.

Expose your own classes


Snippet

Call a UFUNCTION

const FGeneratedWrappedFunction& InFuncDef;
UFunction* Func = InFuncDef.Func;

FStructOnScope FuncParams(Func);

// Calls the ufunction with its parameters allocated inside the struct memory
InObj->ProcessEvent((UFunction*)InFunc, FuncParams.GetStructMemory());

// return value is inside FuncParams
ReturnValue = (const FProperty* Prop, FuncParams.GetStructMemory())

gklua's People

Contributors

delaunay avatar

Watchers

 avatar  avatar

Forkers

kiwi-lang

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.