VIclean
VIclean

Reputation: 165

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

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>'

Upvotes: 1

Views: 6952

Answers (1)

Colonel Thirty Two
Colonel Thirty Two

Reputation: 26569

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.

Upvotes: 2

Related Questions