# Compiling with LUA in Visual Studio

**URL:** <https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621>\
**Category:** The Toolbox\
**Created:** [December 8, 2017, 5:08pm UTC](https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621 "2017-12-08T17:08:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zanos](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zanos/32/422_2.png) [@Zanos](https://discourse.cataclysmdda.org/u/Zanos)\
**Post date:** [December 8, 2017, 5:08pm UTC](https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621/1 "2017-12-08T17:08:19Z")

</div>

I’m having a problem getting LUA to work compiling the build in VS. I downloaded the LUA executables and put them on my path, and I can run lua53 just fine from the command line. I generate the cata\_bindings file and it seems to come out fine. Compiling works.

But when I start up the game lua functions don’t seem to be working correctly. I tested some of the StatsThroughSkills functions in the lua console and it keeps giving me errors like "attempt to call a nil value (field ‘pow’) on line 99. I can use the math.pow function just fine if I start up lua in my command line, though.

Any ideas on why this isn’t working?

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [December 8, 2017, 7:25pm UTC](https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621/2 "2017-12-08T19:25:40Z")

</div>

Can you provide code which you tried to run in the lua console?

---

<div class="post-metadata">

**Author:** ![Zanos](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zanos/32/422_2.png) [@Zanos](https://discourse.cataclysmdda.org/u/Zanos)\
**Post date:** [December 8, 2017, 7:33pm UTC](https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621/3 "2017-12-08T19:33:24Z")

</div>

I just ran calculate\_bonuses(). It’s outputting the first console message but is throwing the math.pow error when it gets into the calc\_bonus(skills\_set) function. It works fine on precompiled builds.

Screenshot of error:

 ![](https://us1.discourse-cdn.com/flex016/uploads/cataclysmdda/original/2X/a/a9b912dd334398a7d95619ffc3d07e4ad364441d.png)

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [December 8, 2017, 7:46pm UTC](https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621/4 "2017-12-08T19:46:12Z")

</div>

Try running following commands in console:

```auto
print(math.pow(3,2))
print(math.abs(-2))
print(tostring(math))

```

What’s the output?

---

<div class="post-metadata">

**Author:** ![Zanos](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zanos/32/422_2.png) [@Zanos](https://discourse.cataclysmdda.org/u/Zanos)\
**Post date:** [December 8, 2017, 7:48pm UTC](https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621/5 "2017-12-08T19:48:13Z")

</div>

![](https://us1.discourse-cdn.com/flex016/uploads/cataclysmdda/original/2X/8/8ff7f857beb3df608bc387021b205604f0446e85.png)

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [December 8, 2017, 7:50pm UTC](https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621/6 "2017-12-08T19:50:39Z")

</div>

Oh, it seems you better use 5.2 instead of 5.3 (or update lua code) - some functions were deprecated in 5.3 (see [http://www.lua.org/manual/5.3/manual.html#8.2](http://www.lua.org/manual/5.3/manual.html#8.2)).

```
The following functions were deprecated in the mathematical library: `atan2`, `cosh`, `sinh`, `tanh`, `pow`, `frexp`, and `ldexp`. You can replace `math.pow(x,y)` with `x^y; you can replace `math.atan2` with `math.atan`, which now accepts one or two parameters; you can replace `math.ldexp(x,exp)` with `x * 2.0^exp`. For the other operations, you can either use an external library or implement them in Lua.
```

---

<div class="post-metadata">

**Author:** ![Zanos](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zanos/32/422_2.png) [@Zanos](https://discourse.cataclysmdda.org/u/Zanos)\
**Post date:** [December 8, 2017, 9:39pm UTC](https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621/7 "2017-12-08T21:39:04Z")

</div>

Replacing math.pow with ^ fixed the problem in that function, but now it’s telling me that the player.str\_max value is nil. [Compiling.md](http://Compiling.md) says to use lua53…

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [December 8, 2017, 10:12pm UTC](https://discourse.cataclysmdda.org/t/compiling-with-lua-in-visual-studio/14621/8 "2017-12-08T22:12:55Z")

</div>

I believe that’s not the issue with compilation - the lua in console works, so it compiled properly with lua support.

As for the syntax used in STS mod - it was apparently written for lua 5.2, but the strange thing how is it even working in precompiled binaries which has Lua 5.3.

Try this in the console:

```auto
print(_VERSION)

```
