public static int print(IntPtr L) { // For each argument we'll 'tostring' it int n = LuaDLL.lua_gettop(L); string s = String.Empty; //LuaDLL.lua_getglobal(L, "debug"); //LuaDLL.lua_getfield(L, -1, "traceback"); //LuaDLL.lua_pushvalue(L, 1); //LuaDLL.lua_pushnumber(L, 2); //LuaDLL.lua_call(L, 2, 1); //n = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "tostring"); for (int i = 1; i <= n; i++) { LuaDLL.lua_pushvalue(L, -1); /* function to be called */ LuaDLL.lua_pushvalue(L, i); /* value to print */ LuaDLL.lua_call(L, 1, 1); if (i > 1) { s += "\t"; } s += LuaDLL.lua_tostring(L, -1); LuaDLL.lua_pop(L, 1); /* pop result */ //LuaDLL.PrintCmd(s); } Debug.Log("LUA: " + s); return(0); }
internal object[] call(object[] args, Type[] returnTypes) { int num = 0; LuaScriptMgr.PushTraceBack(this.L); int num2 = LuaDLL.lua_gettop(this.L); if (!LuaDLL.lua_checkstack(this.L, args.Length + 6)) { LuaDLL.lua_pop(this.L, 1); throw new LuaException("Lua stack overflow"); } this.push(this.L); if (args != null) { num = args.Length; for (int i = 0; i < args.Length; i++) { base.PushArgs(this.L, args[i]); } } int num3 = LuaDLL.lua_pcall(this.L, num, -1, -num - 2); if (num3 != 0) { string text = LuaDLL.lua_tostring(this.L, -1); LuaDLL.lua_settop(this.L, num2 - 1); if (text == null) { text = "Unknown Lua Error"; } throw new LuaScriptException(text, string.Empty); } object[] result = (returnTypes == null) ? this.translator.popValues(this.L, num2) : this.translator.popValues(this.L, num2, returnTypes); LuaDLL.lua_settop(this.L, num2 - 1); return(result); }
public void LuaPop(int amount) { LuaDLL.lua_pop(L, amount); }
public static void Register(IntPtr L) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "GameObject"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "GameObject"); LuaDLL.lua_getglobal(L, "GameObject"); } LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.New, "New"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.CreatePrimitive, "CreatePrimitive"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponent, "GetComponent"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponentInChildren, "GetComponentInChildren"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponentInParent, "GetComponentInParent"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponents, "GetComponents"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponentsInChildren, "GetComponentsInChildren"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponentsInParent, "GetComponentsInParent"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.SetActive, "SetActive"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.CompareTag, "CompareTag"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.FindGameObjectWithTag, "FindGameObjectWithTag"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.FindWithTag, "FindWithTag"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.FindGameObjectsWithTag, "FindGameObjectsWithTag"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.SendMessageUpwards, "SendMessageUpwards"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.SendMessage, "SendMessage"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.BroadcastMessage, "BroadcastMessage"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.AddComponent, "AddComponent"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.Find, "Find"); LuaDLL.lua_pushcsharpproperty(L, "transform", LuaGameObject.get_transform, null); LuaDLL.lua_pushcsharpproperty(L, "layer", LuaGameObject.get_layer, LuaGameObject.set_layer); LuaDLL.lua_pushcsharpproperty(L, "activeSelf", LuaGameObject.get_activeSelf, null); LuaDLL.lua_pushcsharpproperty(L, "activeInHierarchy", LuaGameObject.get_activeInHierarchy, null); LuaDLL.lua_pushcsharpproperty(L, "isStatic", LuaGameObject.get_isStatic, LuaGameObject.set_isStatic); LuaDLL.lua_pushcsharpproperty(L, "tag", LuaGameObject.get_tag, LuaGameObject.set_tag); LuaDLL.lua_pushcsharpproperty(L, "gameObject", LuaGameObject.get_gameObject, null); LuaDLL.lua_getglobal(L, "readIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__index"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_getglobal(L, "writeIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__newindex"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_pushstdcallcfunction(L, new LuaCSFunction(LuaStatic.GameObjectGC)); LuaDLL.lua_setfield(L, -2, "__gc"); LuaDLL.lua_getglobal(L, "Object"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Object"); LuaDLL.lua_getglobal(L, "Object"); LuaDLL.lua_setmetatable(L, -2); } else { LuaDLL.lua_setmetatable(L, -2); } LuaDLL.lua_settop(L, oldTop); LuaStatic.AddTypeDict(typeof(UnityEngine.GameObject)); }
//L: [namespace Table] public bool AddObject(IntPtr L, System.Object obj, string metatable /* nullable */) { IntPtr userdata = IntPtr.Zero; if (luaObjs.TryGetValue(obj, out userdata)) { LuaDLL.lua_rawgeti(L, LuaDLL.LUA_REGISTRYINDEX, weakRefForUserData); //namespace,reftable LuaDLL.lua_pushlightuserdata(L, userdata); //namespace,reftable,userdataKey LuaDLL.lua_rawget(L, -2); //namespace,reftable,userdata LuaDLL.lua_remove(L, -2); //namespace,userdata if (LuaDLL.lua_isuserdata(L, -1)) { return(true); } else { LuaDLL.lua_pop(L, 1); //namespace } } userdata = LuaDLL.lua_newuserdata(L, 1); //namespace,obj if (metatable == null) { Type type = obj.GetType(); while (type != null) { LuaDLL.wlua_getfield(L, -2, type.Name); //namespace,obj,typet if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); //namespace,obj type = type.BaseType; continue; } if (LuaDLL.lua_istable(L, -1)) { metatable = type.Name; break; } else { LuaDLL.lua_pop(L, 2); //namespace throw new LuaException(L, "metatable must be a table:" + type.Name); } } } else { LuaDLL.wlua_getfield(L, -2, metatable); //namespace,obj,typet if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 2); //namespace throw new LuaException(L, "failed to find metatable:" + metatable); } } //namespace,obj,typet LuaDLL.lua_setmetatable(L, -2); //namespace,obj objs[userdata.ToInt64()] = obj; luaObjs[obj] = userdata; LuaDLL.lua_rawgeti(L, LuaDLL.LUA_REGISTRYINDEX, weakRefForUserData); //namespace,obj,reftable LuaDLL.lua_pushlightuserdata(L, userdata); //namespace,obj,reftable,userdatakey LuaDLL.lua_pushvalue(L, -3); //namespace,obj,reftable,userdatakey,obj LuaDLL.lua_rawset(L, -3); //namespace,obj,reftable LuaDLL.lua_pop(L, 1); //namespace,obj return(true); }
/* * Calls the object as a function with the provided arguments and * casting returned values to the types in returnTypes before returning * them in an array */ internal object[] callFunction(object function, object[] args, Type[] returnTypes) { //int nArgs=0; //int oldTop=LuaDLL.lua_gettop(L); //if(!LuaDLL.lua_checkstack(L,args.Length+6)) // throw new LuaException("Lua stack overflow"); //translator.push(L,function); //if(args!=null) //{ // nArgs=args.Length; // for(int i=0;i<args.Length;i++) // { // translator.push(L,args[i]); // } //} //int error = LuaDLL.lua_pcall(L, nArgs, -1, 0); //if (error != 0) // ThrowExceptionFromError(oldTop); //if(returnTypes != null) // return translator.popValues(L,oldTop,returnTypes); //else // return translator.popValues(L, oldTop); int nArgs = 0; LuaDLL.lua_getglobal(L, "traceback"); int oldTop = LuaDLL.lua_gettop(L); if (!LuaDLL.lua_checkstack(L, args.Length + 6)) { LuaDLL.lua_pop(L, 1); throw new LuaException("Lua stack overflow"); } translator.push(L, function); if (args != null) { nArgs = args.Length; for (int i = 0; i < args.Length; i++) { translator.push(L, args[i]); } } int error = LuaDLL.lua_pcall(L, nArgs, -1, -nArgs - 2); if (error != 0) { string err = LuaDLL.lua_tostring(L, -1); LuaDLL.lua_settop(L, oldTop); //LuaTypes luatype = LuaDLL.lua_type(L, -1); LuaDLL.lua_pop(L, 1); if (err == null) { err = "Unknown Lua Error"; } throw new LuaScriptException(err.ToString(), ""); } object[] ret = returnTypes != null?translator.popValues(L, oldTop, returnTypes) : translator.popValues(L, oldTop); LuaDLL.lua_pop(L, 1); return(ret); }
public void LuaPop(int n) { LuaDLL.lua_pop(L, n); }
public static void Register(IntPtr L) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "Transform"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Transform"); LuaDLL.lua_getglobal(L, "Transform"); } LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.SetParent, "SetParent"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.Translate, "Translate"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.Rotate, "Rotate"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.RotateAround, "RotateAround"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.LookAt, "LookAt"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.TransformDirection, "TransformDirection"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.InverseTransformDirection, "InverseTransformDirection"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.TransformVector, "TransformVector"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.InverseTransformVector, "InverseTransformVector"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.TransformPoint, "TransformPoint"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.InverseTransformPoint, "InverseTransformPoint"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.DetachChildren, "DetachChildren"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.SetAsFirstSibling, "SetAsFirstSibling"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.SetAsLastSibling, "SetAsLastSibling"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.SetSiblingIndex, "SetSiblingIndex"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.GetSiblingIndex, "GetSiblingIndex"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.Find, "Find"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.IsChildOf, "IsChildOf"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.FindChild, "FindChild"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.GetEnumerator, "GetEnumerator"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.GetChild, "GetChild"); LuaDLL.lua_pushcsharpproperty(L, "position", LuaTransform.get_position, LuaTransform.set_position); LuaDLL.lua_pushcsharpproperty(L, "localPosition", LuaTransform.get_localPosition, LuaTransform.set_localPosition); LuaDLL.lua_pushcsharpproperty(L, "eulerAngles", LuaTransform.get_eulerAngles, LuaTransform.set_eulerAngles); LuaDLL.lua_pushcsharpproperty(L, "localEulerAngles", LuaTransform.get_localEulerAngles, LuaTransform.set_localEulerAngles); LuaDLL.lua_pushcsharpproperty(L, "right", LuaTransform.get_right, LuaTransform.set_right); LuaDLL.lua_pushcsharpproperty(L, "up", LuaTransform.get_up, LuaTransform.set_up); LuaDLL.lua_pushcsharpproperty(L, "forward", LuaTransform.get_forward, LuaTransform.set_forward); LuaDLL.lua_pushcsharpproperty(L, "rotation", LuaTransform.get_rotation, LuaTransform.set_rotation); LuaDLL.lua_pushcsharpproperty(L, "localRotation", LuaTransform.get_localRotation, LuaTransform.set_localRotation); LuaDLL.lua_pushcsharpproperty(L, "localScale", LuaTransform.get_localScale, LuaTransform.set_localScale); LuaDLL.lua_pushcsharpproperty(L, "parent", LuaTransform.get_parent, LuaTransform.set_parent); LuaDLL.lua_pushcsharpproperty(L, "worldToLocalMatrix", LuaTransform.get_worldToLocalMatrix, null); LuaDLL.lua_pushcsharpproperty(L, "localToWorldMatrix", LuaTransform.get_localToWorldMatrix, null); LuaDLL.lua_pushcsharpproperty(L, "root", LuaTransform.get_root, null); LuaDLL.lua_pushcsharpproperty(L, "childCount", LuaTransform.get_childCount, null); LuaDLL.lua_pushcsharpproperty(L, "lossyScale", LuaTransform.get_lossyScale, null); LuaDLL.lua_pushcsharpproperty(L, "hasChanged", LuaTransform.get_hasChanged, LuaTransform.set_hasChanged); LuaDLL.lua_getglobal(L, "readIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__index"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_getglobal(L, "writeIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__newindex"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_pushstdcallcfunction(L, new LuaCSFunction(LuaStatic.GameObjectGC)); LuaDLL.lua_setfield(L, -2, "__gc"); LuaDLL.lua_getglobal(L, "Component"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Component"); LuaDLL.lua_getglobal(L, "Component"); LuaDLL.lua_setmetatable(L, -2); } else { LuaDLL.lua_setmetatable(L, -2); } LuaDLL.lua_settop(L, oldTop); LuaStatic.AddTypeDict(typeof(UnityEngine.Transform)); }