Skip to content

Commit

Permalink
fix GetType failed problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Salada committed Nov 12, 2015
1 parent a5fa040 commit 2e51795
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Assets/Slua/Script/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static public int CreateClass(IntPtr l)
{
string cls;
checkType(l, 1, out cls);
Type t = Type.GetType(cls);
Type t = LuaObject.FindType(cls);
if (t == null)
{
return error(l, string.Format("Can't find {0} to create", cls));
Expand Down Expand Up @@ -170,7 +170,7 @@ static public int GetClass(IntPtr l)
{
string cls;
checkType(l, 1, out cls);
Type t = Type.GetType(cls);
Type t = LuaObject.FindType(cls);
if (t == null)
{
return error(l, "Can't find {0} to create", cls);
Expand Down
19 changes: 18 additions & 1 deletion Assets/Slua/Script/LuaObject_basetype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,23 @@ public static void pushValue(IntPtr l, LuaTable t)
#region Type
private static Type MonoType = typeof(Type).GetType();

public static Type FindType(string qualifiedTypeName)
{
Type t = Type.GetType(qualifiedTypeName);

if (t != null) {
return t;
}
else {
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {
t = asm.GetType(qualifiedTypeName);
if (t != null)
return t;
}
return null;
}
}

static public bool checkType(IntPtr l, int p, out Type t)
{
string tname = null;
Expand Down Expand Up @@ -561,7 +578,7 @@ static public bool checkType(IntPtr l, int p, out Type t)
if (tname == null)
throw new Exception("expect string or type table");

t = Type.GetType(tname);
t = LuaObject.FindType(tname);
if (t != null && lt==LuaTypes.LUA_TTABLE)
{
LuaDLL.lua_pushstring(l, "__type");
Expand Down

0 comments on commit 2e51795

Please sign in to comment.