Skip to content

Commit cd5b0aa

Browse files
committed
fix interface export
1 parent 937fad3 commit cd5b0aa

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

Assets/Plugins/Slua_Managed/LuaObject_basetype.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,19 @@ public static void pushValue(IntPtr l, ushort v)
157157
{
158158
LuaDLL.lua_pushinteger(l, v);
159159
}
160-
161-
#endregion
162160

163-
#region int
164-
static public bool checkType(IntPtr l, int p, out int v)
161+
#endregion
162+
163+
164+
#region interface
165+
static public void pushInterface(IntPtr l,object i,Type t) {
166+
ObjectCache oc = ObjectCache.get(l);
167+
oc.pushInterface(l, i, t);
168+
}
169+
#endregion
170+
171+
#region int
172+
static public bool checkType(IntPtr l, int p, out int v)
165173
{
166174
v = (int)LuaDLL.luaL_checkinteger(l, p);
167175
return true;

Assets/Plugins/Slua_Managed/LuaState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ public virtual void Dispose(bool dispose)
897897
public static int errorReport(IntPtr L)
898898
{
899899
s.Length = 0;
900+
s.Append(LuaDLL.lua_tostring(L,1));
900901

901902
LuaDLL.lua_getglobal(L, "debug");
902903
LuaDLL.lua_getfield(L, -1, "traceback");

Assets/Plugins/Slua_Managed/ObjectCache.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ internal int allocID(IntPtr l,object o) {
251251
return index;
252252
}
253253

254+
internal void pushInterface(IntPtr l, object o, Type t)
255+
{
256+
257+
int index = allocID(l, o);
258+
if (index < 0)
259+
return;
260+
261+
LuaDLL.luaS_pushobject(l, index, getAQName(t), true, udCacheRef);
262+
}
263+
264+
254265
internal void push(IntPtr l, object o, bool checkReflect)
255266
{
256267

Assets/Slua/Editor/LuaCodeGen.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,6 +2357,8 @@ void WritePushValue(Type t, StreamWriter file)
23572357
{
23582358
if (t.IsEnum)
23592359
Write(file, "pushEnum(l,(int)ret);");
2360+
else if (t.IsInterface && t.IsDefined(typeof(CustomLuaClassAttribute), false))
2361+
Write(file, "pushInterface(l,ret, typeof({0}));", TypeDecl(t));
23602362
else
23612363
Write(file, "pushValue(l,ret);");
23622364
}
@@ -2365,10 +2367,11 @@ void WritePushValue(Type t, StreamWriter file, string ret)
23652367
{
23662368
if (t.IsEnum)
23672369
Write(file, "pushEnum(l,(int){0});", ret);
2370+
else if (t.IsInterface && t.IsDefined(typeof(CustomLuaClassAttribute),false))
2371+
Write(file, "pushInterface(l,{0}, typeof({1}));", ret,TypeDecl(t));
23682372
else
23692373
Write(file, "pushValue(l,{0});", ret);
2370-
}
2371-
2374+
}
23722375

23732376
void Write(StreamWriter file, string fmt, params object[] args)
23742377
{

Assets/Slua/Resources/custom.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ function main()
2525
print("-->"..c:getItem("test"))
2626

2727
assert(c:getInterface():getInt()==10)
28+
c:getInterface():setInt(11)
2829
print("assert interface ok")
2930
end

Assets/Slua/example/Custom.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,30 @@ public string getTypeName(Type t)
7575
public interface IFoo
7676
{
7777
int getInt();
78+
void setInt(int i, bool ok);
7879
}
7980

8081
class Foo : IFoo {
8182
public int getInt() {
8283
return 10;
8384
}
85+
public void setInt(int i,bool ok) {
86+
87+
}
8488
}
8589

8690
public IFoo getInterface() {
8791
return new Foo();
8892
}
89-
9093
}
9194

95+
public static class IFooExt
96+
{
97+
public static void setInt(this Custom.IFoo f, int i)
98+
{
99+
100+
}
101+
}
92102

93103
namespace SLua {
94104

0 commit comments

Comments
 (0)