Forum Replies Created
-
AuthorPosts
-
Always the pessimist!
I’ll have a look at it tonight.Edit: Done. Now using the official 5.3.3 release.
It’s linked as a git submodule, which also includes the commit hash. Even if they change something, it will still point to the same version.
Edit: Technically I could grab the “pure” source from lua.org, but I like being able to link to it. I don’t think luadist is maintained by the Lua devs, but it seems to have the official source. If there are ever problems I’ll copy/paste it from lua.org, but for now it works.
Update:
You can now execute scripts (use DoString(LoadString("asset::file.lua")) rather than DoFile, for now). Objects and structs will have a magic metatable assigned to them by default, but at the moment only objects can get/set fields. I’m having some issues trying to manipulate structs with an interface.Defining GetField/ SetField is a little verbose at this point, but eventually this should clear up if/when we get reflection. I’m using void pointers in the interface to avoid method generics at this stage.
I’ll doc and zip and upload for the module manager at some point.
WIP of a slightly more Monkeyish API, but still a ways to go (yuck at all the required pointers!)
There’s now a LuaState class that wraps lua_State Ptr and makes it a little more object-oriented. However, you still need to call LuaState.NewState to create a new state rather than New LuaState. The reasoning behind this is that since function pointers still need to match Int(lua_State Ptr), you can use New LuaState(L) to avoid using the raw C functions.Short-term Roadmap:
- Finish wrapping the C functions
- Make it less verbose to push/pop MX2 objects and structs
- Wrap the Lua table data type
- Metatable black magic to allow back and forth mapping of methods/fields/functions when manipulating MX2 objects and structs in Lua
- Bind Lua tables to MX2 Lists and Maps?
Long-term Roadmap:
- Introduce an easy way of binding full modules
- Debug support
- More to come?
@therevills: That’s a while off, yet. There’s a lot of magic bridging I’d like to get working first. For example, I want tables to act as if they were MX2 containers. I should be able to index a Lua table and have it pass through to MX2 List[index], or Map[key]. I’m not sure how to handle mapping generics in that case, though.
Mapping the existing MX2 modules is a huge task, and a little unnecessary at this stage. The primary reason for embedding Lua is to add scripting to your game logic (enemies, bullets, GUI, etc.), not to run your full Mojo game loop.
I can only ezmode the embedded interface so much, though. At some point the developer will need to know how to bind objects. Just executing some Lua won’t do much for you.
I’ll set aside some time this weekend to get heavily into wrapping the core libraries and/or simplifying the Lua API for the less savvy amongst us. I just want to be careful how I implement it so that it’s as lightweight and extensible as possible.
Edit: Just pushed some changes that let you push/pop MX2 structs and classes. It’s not at a scriptable stage yet, but it’s well on the way.
Cool.
Don’t go too crazy just yet, I still need to add the userdata/metatable magic to let you do stuff like:[/crayon]Monkey12345[crayon-5cba8aed0d938746294737 inline="true" ]require"mojo"function dostuff(canvas)canvas.Color = Color(255, 0, 255)canvas.DrawRect(10, 10, 100, 100)endIt’s most likely going to be something like:
mx2lua_registermodule(L, New MojoLuaModule)
Which will register all the functions and classes in the mojo module.I’ve been really busy at the moment with Infinity Evolved Expert.
Edit: If you want to contribute, fork and make a pull request.
Edit 2: Adding full debug support is non-trivial, since you’ll have to hook up all of the lua_Debug functions. They’re externed, but it’s not as simple as just switching it on.Nice work. I’d like to see some decent tutorials on externs in MX2 though. I’m wrapping some existing code at the moment (which builds), but my test program refuses to link, even though it’s clearly including the .a file (OS X, El Capitan).
According to Git blame, Clear has always required a Color struct.
https://github.com/blitz-research/monkey2/blame/master/modules/mojo/graphics/canvas.monkey2#L198
I guess I’ve been spoiled somewhat with Swift’s optionals recently. Adding something like that would be a huge undertaking, and I would expect it in version 2.0 at the earliest.
Sure, in that example it’s “clear”, but in my situation it was one of ten or so fields in a class, that was supposed to be assigned later in the app lifecycle. I was trying to access the field before it got to that stage. If it had thrown an actual exception on the method call, I would have been able to track it down sooner.
If code in a method is executing, I would expect that the object exists to actually call it.
Can’t you inline some of those checks anyway?
Could you make it some kind of pragma that only does runtime checks in debug mode?Is that not needed on Mac or something? I’ve been building fine on v009 and v010.
Having said that, App.RequestRender() started giving memory exceptions, so I had to rebuild all the modules…That’s a pity, some other languages can infer from the return type.
I guess a “Get” method will have to be good enough.Whether or not it’s by design, you should never be able to call a method on a non-existent object. This isn’t Objective-C where you can send a message to nil.
@therevills: That’s basically what I wanted.
Edit: Ooohhh putting an @ creates a link to the user’s profile. -
AuthorPosts