lua与C#交互

C#调用lua:

l = new LuaSvr();
l.init(tick,complete,LuaSvrFlag.LSF_DEBUG);
  l.start("main");
object o = l.luaState.getFunction("foo").call(1, 2, 3);
object[] array = (object[])o;
for (int n = 0; n < array.Length; n++)
Debug.Log(array[n]);


lua调用C#:
类名前加 [CustomLuaClass]
方法要静态公有 

使用工具编译成lua_helloworld.cs

[CustomLuaClass]
public class HelloWorld
{
public UnityEngine.Events.UnityAction someAct;
    static public void WriteStr(string str)
{ Debug.Log("WriteStr" + str);
}


===========================================分割线

编译后

  [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static public int WriteStr_s(IntPtr l)
{
    try {
System.String a1;
checkType(l,1,out a1);
HelloWorld.WriteStr(a1);
pushValue(l,true);
return 1;
}
catch(Exception e)
{ return error(l,e); }
}




=====================================分割线

HelloWorld.WriteStr(" 123 ") 
        

你可能感兴趣的:(lua)