Mervill / Unity3D-NLua

Everything you need to get started using Lua in Unity3D. Indie & Pro compatible.
Boost Software License 1.0
190 stars 50 forks source link

Example scene doesn't work with KeraLua in Unity Pro #4

Closed karlmarxman closed 9 years ago

karlmarxman commented 10 years ago

Changing define to USE_KERALUA and the example scene is unable to GetComponent in function Start() as well as anything in Update. No other changes made. Is there anything else required to switch to KeraLua?

sonygod commented 10 years ago

+1 got the same problem in unity.

EntryPointNotFoundException: luanet_registryindex KeraLua.Lua.LuaNetRegistryIndex () NLua.LuaIndexes.get_Registry () NLua.Lua.Init () NLua.Lua..ctor () ExampleBehaviour.Awake () (at Assets/Example/ExampleBehaviour.cs:77)

use

UNITY_3D;USE_KERALUA;LUA_CORE;

Mervill commented 10 years ago

Are you using the dll's provided in /Assets/plugins? The standard Lua DLL won't work with Unity.

Two things I'd suggest:

  1. Trying removing the version of the DLL your not using from plugins. IE if your using the x86 version then remove the x64 version.
  2. Take the x86 version of the dll and move it to the root directory so your project directory looks like:
Assets/
ProjectSettings/
lua52.dll
<...>

If you get errors involving string functions try adding WSTRING to your compilation arguments.

karlmarxman commented 10 years ago

Using the dlls from Assets/Plugins. I tried all 3 suggestions and didn't change the default scene's errors. Note I get a different error message: "invalid arguments to method: TestBehaviour.GetComponent Lua (at [string "chunk"]:11)" and so on for everything in the example scene. Though the first thing in function Start "Debug.Log(ExampleBehaviour)" works fine oddly enough.

rje commented 9 years ago

I also see the "invalid arguments to method: TestBehaviour.GetComponent. I've seen this behavior replicated in my own project when attempting to call any static C# function with a string parameter.

e.g. this will work in kopilua, but fail in keralua:

Double = luanet.import_type("System.Double") result = Double.TryParse("1.05")

Curiously, a member function that takes a string parameter works fine, e.g:

StringBuilder = luanet.import_type("System.Text.StringBuilder") sb = StringBuilder() sb.Append("foo")

rje commented 9 years ago

I spent some time digging through this today, and found that it appeared to be a problem in LuaLib.LuaNetIsStringStrict() not working as intended. I replaced all references to that call in CheckType.cs with calls to LuaLib.LuaIsString() and my scripts now all function as intended.

viniciusjarina commented 9 years ago

Hello @rje this seems to work on current version of NLua/NLua http://screencast.com/t/wBbMDO4i @Mervill can you bump Unity3D-NLua to tip of master?

If anyone could repro this on NLua/NLua a test case would be great. :smile:

rje commented 9 years ago

@viniciusjarina I can try to update to current nlua this week and see if I can repro the issue. Seems like it'd make sense for @Mervill to bump to tip of master either way

Mervill commented 9 years ago

Hello everyone!

After updating NLua, the fix suggested by @rje resolved the issue. This is most likely an issue with Unity's mono implementation. I'm uploading the fix for now, (https://github.com/Mervill/Unity3D-NLua/commit/bfc87e0fc60a1921dbfb1cbc7de552c548371e10) but I'll do some more investigation before I suggest pushing upstream.

sonygod commented 9 years ago

after define KeraLua in unity pc platform ,it's work ,but android not work? any help?

after switch to android

DllNotFoundException: D:/Download/Unity3D-NLua-master/Assets/Plugins/x86/lua52.dll KeraLua.Lua.LuaLNewState () (at Assets/KeraLua/Lua.cs:33) NLua.LuaLib.LuaLNewState () (at Assets/NLua/LuaLib/LuaLib.cs:77) NLua.Lua..ctor () (at Assets/NLua/Lua.cs:278) TestBehaviour.Awake () (at Assets/Example/TestBehaviour.cs:26)

Mervill commented 9 years ago

This should work fine now, recompiling the lua52 dll seems to have solved it.