Skip to content

bLuaUserData

bLuaUserData is a static class that has helper functions related to registering and creating userdata in Lua from C# objects.

The only way Lua can access C# code from Lua code is if the C# code is first registered as userdata (a Lua concept). The way bLua allows you to register userdata is by marking C# classes with the bLuaUserDataAttribute, like the example below.

[bLuaUserData]
public class MyUserData
{
    public int numberProperty;

    public void LogSomething(string text)
    {
        Debug.Log(text)
    }
}

More examples of userdata and how to access it on the "Getting Started" page.

bLuaInstances will automatically register all C# classes marked as userdata by default. If you want to register specific types manually or at a later time than the instance's creation, you can use the AutoRegisterTypes setting and manually call Register or RegisterAllBLuaUserData.


Static Methods

Register

Registers a given type on the given bLuaInstance.

RegisterAllBLuaUserData

Registers all types in the project that are marked with the bLuaUserDataAttribute on the given bLuaInstance. This is run automatically on bLuaInstances by default when they are created.

IsUserData

Returns true if the given type is marked with the bLuaUserDataAttribute, which allows it to be registered as userdata.

IsUserDataRegistered

Returns true if the given type is registered on the given bLuaInstance.


Attributes

bLuaUserData

This attribute goes on classes and allows the type to be registered as userdata on a bLuaInstance.

bLuaHidden

This attribute goes on methods, properties, and fields, and will hide them from being accessible in Lua as userdata. For example, if you have a class Character that is marked as userdata with [bLuaUserData], and a method on that class Debug_TakeDamage that is marked with [bLuaHidden], the Debug_TakeDamage method will not be accessible from Lua.

bLuaParam_Ignored

This attribute goes on parameters in methods, and will cause the parameter to be ignored when registering the method as userdata. For example, if you have a method on a userdata class with two parameters, the first marked with [bLuaParam_Ignored], and the second without that attribute, Lua can call that function as if only the second parameter existed. On the C# side, the first parameter will never be filled with data from Lua but could still be called from C# with that parameter filled.

bLuaParam_State

This attribute goes on parameters in methods of type IntPtr. This attribute does all of the same things as [bLuaParam_Ignored] but will automatically fill the parameter with the calling Lua state of the Lua thread that called the userdata method. This is mostly used for internal bLua features.