Skip to content

Bindding

tianlelu edited this page Jan 30, 2019 · 3 revisions

###Lua can access blueprint class or function.For those aren't blueprint, you can write some simple code to do help.

struct ExampleStruct
{
    int VarInterger;
    UObject* VarPointer;
    FVector VarStruct;
    float MemberFunc(int p1, FVector& p2, UObject* p);
    static void StaticFunc();
};
// Binding Code
LUA_GLUE_BEGIN(ExampleStruct) //class name
LUA_GLUE_PROPERTY(VarInterger) //member property
LUA_GLUE_PROPERTY(VarPointer)
LUA_GLUE_PROPERTY(VarStruct)
LUA_GLUE_FUNCTION(MemberFunc) //member function
LUA_GLUE_FUNCTION(StaticFunc)
LUA_GLUE_END()
struct ExampleCtor
{
    ExampleCtor(int, float);
    ExampleCtor(string);
};
// 
LUA_GLUE_BEGIN(ExampleCtor)
LUA_GLUE_CTOR((int, float)) //construction function binding
LUA_GLUE_CTOR((string))
LUA_GLUE_END()
struct ExampleOverload
{
    void Func(float);
    void Func(int);
};

LUA_GLUE_BEGIN(ExampleOverload)
//overload function binding
LUA_GLUE_OVERLOAD(Func, void(ExampleOverload::*)(float))
LUA_GLUE_OVERLOAD(Func, void(ExampleOverload::*)(int))
LUA_GLUE_END()
struct ExampleDefault
{
    ExampleDefault(int = 1);
    void Func(float=2.0);
};
// function with default arguments
LUA_GLUE_BEGIN(ExampleDefault)
LUA_GLUE_CTOR((int), 1)  //construct function
LUA_GLUE_FUNCTION(Func, 2.0) //member function
LUA_GLUE_END()
// class with parent
struct Parent{}; //parent
struct Child{};

LUA_GLUE_BEGIN(Parent) //first binding parent
LUA_GLUE_END()

LUA_GLUE_BEGIN(Child) //then binding child
LUA_GLUE_END(Parent) //add parent name to the macro

more examples

  1. please take a look to TestCaseActor.h
  2. and take a look to the LuaManuallyGlue plugin
  3. if you want to write slate by lua, you can have a look to editormain.lua and the plugin LuaEditorPlugins
Clone this wiki locally