문제

I'm starting out to learn Lua script usage in Java via LuaJava; my IDE is Eclipse.

But when I execute this simple Hello World snippet there is no output in the Eclipse console.

Took the code snippet from here

package com.cpg.lua;

import org.keplerproject.luajava.LuaState;
import org.keplerproject.luajava.LuaStateFactory;

public class Hello
{
public static void main(String[] args)
{ 
  LuaState luaState;
  luaState = LuaStateFactory.newLuaState();
  luaState.openLibs();
  luaState.LdoFile("hello.lua");
  luaState.close();
}
}

hello.lua

function hello()
    print("Hello World from Lua!") 
end

hello()

But the script beneath works perfectly well.

hello2.lua

print("Hello World from Lua!") 

Anyone know why the script with the function definition inside does nothing when called from Java but when executed through the console works perfectly?

도움이 되었습니까?

해결책

I haven't tried or seen a function called like that. But you can call the hello() function from the Java like this:

LuaState l = LuaStateFactory.newLuaState();
l.doFile("main.lua");
l.getGlobal("hello");
l.call(0, 0);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top