LuaInterface error " '=' expected near '<eof>' "

6.5k views Asked by At

I'm trying to learn lua and how lua can be used with C#. So I've created a lua script in which I declared a string variable called "x":

local x = "String variable"

Then I've tried to load the string from the c# program like this:

LuaFunction vsa =  lua.LoadString("x", "root.lua");

When I try to compile I receive this error:

[string "root.lua"]:1: '=' expected near '<eof>'

1

There are 1 answers

2
Colonel Thirty Two On BEST ANSWER

The function you are trying to make is basically this:

function(...)
    x
end

This function isn't valid; You're reading x but not doing anything with it, and since Lua expressions can't exist as statements, you get a parse error.

What you meant is probably lua.LoadString("return x", "root.lua"). However, this still won't work, because x is local to the file which you defined it in; outside functions can't access it. Either x needs to be global or (more preferably) you define a getter function inside the file that you define x in.