-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scripting #466
base: master
Are you sure you want to change the base?
Add scripting #466
Conversation
f52a5bf
to
a849c3a
Compare
18174db
to
a45116c
Compare
Console will read scripts from resources/commands Also create Console class.
I'm not sure that now is the best time for this, and there are some issues to work out with whatever scripting language we use. The primary use case for it will be scripting in mods, and mods scripts will need to be deterministic just like the rest of the game code, in order for multiplayer to work. This means they will need to use our FixedPoint class for maths. Given that, I'm not sure if we shoudl try to hack FixedPoint into an existing scriping language, or if we should just make our own simplistic langauge. In particular, since FixedPoints can be a bit slow, it would be nice to use a language that distinguished between integer and real number types, so people could only use FixedPoint operations when they actually needed them. |
That said, if you want to hack around and experiment with integrating FixedPoint into lua / other languages, please go ahead, but given the issues, I don't think it will be merged until we are looking adding proper mod support, probably after 1.0. |
I was planning to use this to implement the quest system. As for the FixedPoint class, it is fairly easy to integrate C++ classes into Lua, and Lua would execute C++ functions when we use the class' methods inside it. |
The thing is, we would want lua to use that class for all of its maths. So, if a script tries to add two numbers, it should use FixedPoints internally instead of floats, which is not as simple as just adding a native binding for the class. |
Added FixedType registration for use in Lua. Also added unit tests to test it. |
Added unit tests.
http://lua.2524044.n2.nabble.com/Fixed-point-LUA-NUMBER-td7630153.html is a good thread on the topic, and is talking more abotu what I'm getting at. We would need to bundle our own copy of lua (in the extern/ folder), and redefine it's internal number type using the LUA_NUMBER #define. The maths module will break, so we can just remove it for now. Or we could go for the other more moderate approach listed there of redefinign LUA_NUMBER to int32_t and keeping the custom fixedpoint class you've added. |
Lua 5.3 added support to 64 bit integers, so I don't think it it necessary anymore. |
It culd still be worth trying out defining LUA_NUMBER to FixedPoint, even in 5.3, see https://github.com/lua/lua/blob/v5.3.5/luaconf.h#L457, and https://github.com/lua/lua/blob/v5.3.5/luaconf.h#L127 This might be perfect actually, as the lua interpreter will try to use normal integer operations, but fall back to FixedPoint where necessary. Of course, we would also need to compile lua as c++, so that it could use the operator overloading of the FixedPoint class. |
git-subtree-dir: extern/lua git-subtree-split: 9b7987a9d1471ba94764286b28e0998f73deb46a
Just broke something, and couldn't figure out what.
Added FixedPoint to lua. Now all floating point operations and math functions use FixedPoint. Still need to implement some missing math functions that are not present in FixedPoint (log, exp, ...), implement the modulo (%) operator, and fix printing to stdout. |
TODO: Fix printing to stdout
34189dd
to
11e80ea
Compare
I'm getting "ERROR INVALID SPRITE CACHE REQUEST 1" when I try to open the console since #429 got merged. |
Removed Singleton from LuaScript
git-subtree-dir: extern/LuaBridge git-subtree-split: 24f1877f967cc138c780ed78a23e03a490a9aec9
Add some docs on how to add C++ classes to Lua.
Wtf? PR just closed on its own. |
Got me all excited, it'll be fun to play with this once it's ready for an audience |
Just so you know, I think things are looking decent here, and I haven't forgotten about the PR, but for now it won't be merged. There will come a time in the implementation of the game when we will need a scripting engine, and at that point this will be pulled in. I'm not sure when that will be, maybe when we first start to add mods, or quests or some other point, but it will happen. For now though, there's no need to have it in the main tree before it's in use. |
Is scripting done? Is it working? I'm assuming it's using LUA? |
This is a modified version of lua which is mostly ready to be integrated. Scripting being "donw" would mean that ypu can actually do something with it (like add custom lua scripts into the game), which is not yet done, and won't be for a while, as the priority is getting the base game working properly. |
Attempt to fix #22.
I only gonna work on this in my spare time, so this should take a while.