MCPcopy Create free account
hub / github.com/Tencent/xLua / LoadFromResource

Function LoadFromResource

Assets/XLua/Src/StaticLuaCallbacks.cs:684–713  ·  view source on GitHub ↗
(RealStatePtr L)

Source from the content-addressed store, hash-verified

682
683#if !XLUA_GENERAL
684 [MonoPInvokeCallback(typeof(LuaCSFunction))]
685 internal static int LoadFromResource(RealStatePtr L)
686 {
687 try
688 {
689 string filename = LuaAPI.lua_tostring(L, 1).Replace('.', '/') + ".lua";
690
691 // Load with Unity3D resources
692 UnityEngine.TextAsset file = (UnityEngine.TextAsset)UnityEngine.Resources.Load(filename);
693 if (file == null)
694 {
695 LuaAPI.lua_pushstring(L, string.Format(
696 "\n\tno such resource '{0}'", filename));
697 }
698 else
699 {
700 if (LuaAPI.xluaL_loadbuffer(L, file.bytes, file.bytes.Length, "@" + filename) != 0)
701 {
702 return LuaAPI.luaL_error(L, String.Format("error loading module {0} from resource, {1}",
703 LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1)));
704 }
705 }
706
707 return 1;
708 }
709 catch (System.Exception e)
710 {
711 return LuaAPI.luaL_error(L, "c# exception in LoadFromResource:" + e);
712 }
713 }
714
715 [MonoPInvokeCallback(typeof(LuaCSFunction))]
716 internal static int LoadFromStreamingAssetsPath(RealStatePtr L)

Callers

nothing calls this directly

Calls 5

lua_tostringMethod · 0.80
lua_pushstringMethod · 0.80
xluaL_loadbufferMethod · 0.80
luaL_errorMethod · 0.80
ReplaceMethod · 0.45

Tested by

no test coverage detected