|
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...
|
|
Definition at line 10 of file LuaUserData.cs.
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 List
1 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 List
1 object into a userdata.
- Parameters
-
scriptObject | Lua value to convert and wrap in a userdata. |
desiredType | Type 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.