0

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!

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by 0x69
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.