From fb3ac694691956e9808342d269b488bcd4afec91 Mon Sep 17 00:00:00 2001 From: pangweiwei Date: Wed, 1 Jul 2015 22:18:28 +0800 Subject: [PATCH] revert dostring,fix main.txt error --- Assets/Slua/Resources/main.txt | 5 ----- Assets/Slua/Script/LuaState.cs | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Assets/Slua/Resources/main.txt b/Assets/Slua/Resources/main.txt index bbf6e13c..6456c1ff 100644 --- a/Assets/Slua/Resources/main.txt +++ b/Assets/Slua/Resources/main.txt @@ -25,11 +25,6 @@ function main() print("using lua") end - HelloWorld.depth= "a" - print(HelloWorld.depth) - HelloWorld.priority=1 - print(HelloWorld.priority) - -- test custom component local x=UnityEngine.GameObject("OoOo") x:AddComponent(SLuaTest) diff --git a/Assets/Slua/Script/LuaState.cs b/Assets/Slua/Script/LuaState.cs index 90f07978..f5ec3070 100644 --- a/Assets/Slua/Script/LuaState.cs +++ b/Assets/Slua/Script/LuaState.cs @@ -522,10 +522,10 @@ static int init(IntPtr L) return unpack(ret) end "; - // overload resume function for report error - if (LuaDLL.lua_dostring(L, resumefunc) != 0) - LuaObject.lastError(L); + // overload resume function for report error + LuaState.get(L).doString(resumefunc); + LuaDLL.lua_pushcfunction(L, dofile); LuaDLL.lua_setglobal(L, "dofile"); @@ -708,6 +708,17 @@ internal static int dofile(IntPtr L) } return 0; } + + public object doString(string str) + { + byte[] bytes = Encoding.UTF8.GetBytes(str); + + object obj; + if (doBuffer(bytes, "temp buffer", out obj)) + return obj; + return null; ; + + } [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] internal static int loader(IntPtr L)