Barotrauma Client Doc
Barotrauma.LuaUserData Class Reference

Static Public Member Functions

static Type GetType (string typeName)
 
static IUserDataDescriptor RegisterType (string typeName)
 
static bool IsRegistered (string typeName)
 
static void UnregisterType (string typeName, bool deleteHistory=false)
 
static IUserDataDescriptor RegisterGenericType (string typeName, params string[] typeNameArguements)
 
static void UnregisterGenericType (string typeName, params string[] typeNameArguements)
 
static bool IsTargetType (object obj, string typeName)
 
static string TypeOf (object obj)
 
static object CreateStatic (string typeName)
 
static object CreateEnumTable (string typeName)
 
static void MakeFieldAccessible (IUserDataDescriptor IUUD, string fieldName)
 
static void MakeMethodAccessible (IUserDataDescriptor IUUD, string methodName, string[] parameters=null)
 
static void MakePropertyAccessible (IUserDataDescriptor IUUD, string propertyName)
 
static void AddMethod (IUserDataDescriptor IUUD, string methodName, object function)
 
static void AddField (IUserDataDescriptor IUUD, string fieldName, DynValue value)
 
static void RemoveMember (IUserDataDescriptor IUUD, string memberName)
 
static DynValue CreateUserDataFromDescriptor (DynValue scriptObject, IUserDataDescriptor desiredTypeDescriptor)
 See CreateUserDataFromType. More...
 
static DynValue CreateUserDataFromType (DynValue scriptObject, Type desiredType)
 Converts a Lua value to a CLR object of a desired type and wraps it in a userdata. If the type is not registered, then a new MoonSharp.Interpreter.Interop.StandardUserDataDescriptor will be created and used. The goal of this method is to allow Lua scripts to create userdata to wrap certain data without having to register types. More...
 

Detailed Description

Definition at line 10 of file LuaUserData.cs.

Member Function Documentation

◆ AddField()

static void Barotrauma.LuaUserData.AddField ( IUserDataDescriptor  IUUD,
string  fieldName,
DynValue  value 
)
static

Definition at line 264 of file LuaUserData.cs.

◆ AddMethod()

static void Barotrauma.LuaUserData.AddMethod ( IUserDataDescriptor  IUUD,
string  methodName,
object  function 
)
static

Definition at line 246 of file LuaUserData.cs.

◆ CreateEnumTable()

static object Barotrauma.LuaUserData.CreateEnumTable ( string  typeName)
static

Definition at line 96 of file LuaUserData.cs.

◆ CreateStatic()

static object Barotrauma.LuaUserData.CreateStatic ( string  typeName)
static

Definition at line 82 of file LuaUserData.cs.

◆ CreateUserDataFromDescriptor()

static DynValue Barotrauma.LuaUserData.CreateUserDataFromDescriptor ( DynValue  scriptObject,
IUserDataDescriptor  desiredTypeDescriptor 
)
static

See CreateUserDataFromType.

Parameters
scriptObjectLua value to convert and wrap in a userdata.
desiredTypeDescriptorDescriptor of the type of the object to convert the Lua value to. Uses MoonSharp ScriptToClr converters.
Returns
A userdata that wraps the Lua value converted to an object of the desired type as described by desiredTypeDescriptor .

Definition at line 293 of file LuaUserData.cs.

◆ CreateUserDataFromType()

static DynValue Barotrauma.LuaUserData.CreateUserDataFromType ( DynValue  scriptObject,
Type  desiredType 
)
static

Converts a Lua value to a CLR object of a desired type and wraps it in a userdata. If the type is not registered, then a new MoonSharp.Interpreter.Interop.StandardUserDataDescriptor will be created and used. The goal of this method is to allow Lua scripts to create userdata to wrap certain data without having to register types.

Wrapping the value in a userdata preserves the original type during script-to-CLR conversions.

A Lua script needs to pass a List1 to a CLR method expecting System.Object, MoonSharp gets in the way by converting the List1 to a MoonSharp.Interpreter.Table and breaking everything. Registering the List1 type can break other scripts relying on default converters, so instead it is better to manually wrap the List1 object into a userdata.

Parameters
scriptObjectLua value to convert and wrap in a userdata.
desiredTypeType describing the CLR type of the object to convert the Lua value to.
Returns
A userdata that wraps the Lua value converted to an object of the desired type.

Definition at line 312 of file LuaUserData.cs.

◆ GetType()

static Type Barotrauma.LuaUserData.GetType ( string  typeName)
static

◆ IsRegistered()

static bool Barotrauma.LuaUserData.IsRegistered ( string  typeName)
static

Definition at line 26 of file LuaUserData.cs.

◆ IsTargetType()

static bool Barotrauma.LuaUserData.IsTargetType ( object  obj,
string  typeName 
)
static

Definition at line 65 of file LuaUserData.cs.

◆ MakeFieldAccessible()

static void Barotrauma.LuaUserData.MakeFieldAccessible ( IUserDataDescriptor  IUUD,
string  fieldName 
)
static

Definition at line 129 of file LuaUserData.cs.

◆ MakeMethodAccessible()

static void Barotrauma.LuaUserData.MakeMethodAccessible ( IUserDataDescriptor  IUUD,
string  methodName,
string[]  parameters = null 
)
static

Definition at line 169 of file LuaUserData.cs.

◆ MakePropertyAccessible()

static void Barotrauma.LuaUserData.MakePropertyAccessible ( IUserDataDescriptor  IUUD,
string  propertyName 
)
static

Definition at line 227 of file LuaUserData.cs.

◆ RegisterGenericType()

static IUserDataDescriptor Barotrauma.LuaUserData.RegisterGenericType ( string  typeName,
params string[]  typeNameArguements 
)
static

Definition at line 49 of file LuaUserData.cs.

◆ RegisterType()

static IUserDataDescriptor Barotrauma.LuaUserData.RegisterType ( string  typeName)
static

Definition at line 14 of file LuaUserData.cs.

◆ RemoveMember()

static void Barotrauma.LuaUserData.RemoveMember ( IUserDataDescriptor  IUUD,
string  memberName 
)
static

Definition at line 276 of file LuaUserData.cs.

◆ TypeOf()

static string Barotrauma.LuaUserData.TypeOf ( object  obj)
static

Definition at line 75 of file LuaUserData.cs.

◆ UnregisterGenericType()

static void Barotrauma.LuaUserData.UnregisterGenericType ( string  typeName,
params string[]  typeNameArguements 
)
static

Definition at line 57 of file LuaUserData.cs.

◆ UnregisterType()

static void Barotrauma.LuaUserData.UnregisterType ( string  typeName,
bool  deleteHistory = false 
)
static

Definition at line 38 of file LuaUserData.cs.