Hey everyone, as the title suggests I'm trying to find a function or some code that'll execute a string of code in Lua. If anyone is familiar with Python, It would be the eval function. ex:

eval("y=1")
print(y)
>>> 1

Essentially, I'd like to do that same thing in Lua.

BTW sorry if I posted in the wrong area, Daniweb has no Lua forum and game development would be the closest area to it since it is used allot for scripting in game engines. Any help is appreciated, Thanks!

Hey everyone, as the title suggests I'm trying to find a function or some code that'll execute a string of code in Lua. If anyone is familiar with Python, It would be the eval function. ex:

eval("y=1")
print(y)
>>> 1

Essentially, I'd like to do that same thing in Lua.

You're looking for luaL_dostring, in the auxiliary library. Should do exactly what you're looking for.

BTW sorry if I posted in the wrong area, Daniweb has no Lua forum and game development would be the closest area to it since it is used allot for scripting in game engines. Any help is appreciated, Thanks!

For future reference, Lua questions might fit better in the "Legacy and Other Languages" forum.

--smg

Hey everyone, as the title suggests I'm trying to find a function or some code that'll execute a string of code in Lua.

LoadString()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.