-2

I have this script loaded in my C# program

function test()
    print ("A")
end

but when I try to invoke it

LuaFunction func = lua.GetFunction("test")

func.call()

I get the problem that func is null.

What do I wrong?

user507410
  • 512
  • 4
  • 12

1 Answers1

1

You say you have loaded the test script into the C# program. This is not enough. You have to execute the resulting chunk code so that the global test variable gets assigned.

Always reminder that

function test()
    print ("A")
end

is only a syntactic sugar for:

test = function()
    print ("A")
end

When Lua loads some code, it just compiles the source code into bytecode.The affectation test = function() end is only executed at runtime, not at compile time.

prapin
  • 6,395
  • 5
  • 26
  • 44