Page 1 of 1

Minetest, Luajit, and Javascript

PostPosted: 25 Oct 2016, 02:57
by dulsi
My son took a simple "Coding with Minecraft" class at the public library. It used scriptcraft mod for minecraft. We don't have minecraft at home so I was thinking of modifying minetest to run some scriptcraft code.

(Why do this? Wouldn't it be easier to teach your son lua? Yes it probably would. It could probably build equivalent lua functions that he used very easily. Mapping minecraft block IDs would minetest values would be annoying but would need to be done if javascript is implemented. Alternatively I could modify the api to use minetest values which would be easier but even less compatible with scriptcraft. So in other words, this idea is much harder than it needs to be. Now we return to original discussion where I'm trying to do this despite it being harder.)

I found instructions for calling a C shared library very easily for lua. I tried the code in minetest and it failed. Minetest uses luajit not lua. Luajit has ffi to easily call a C function but I don't see anything to call back into luajit. Ideally I want to run C function for example which run javascript. When javascript hits box('5'), it calls back to C which calls back to luajit to place a block. Is it possible to do this in luajit?

EDIT: Found how to do it. It has the same api that lua has you just need to include/link to the luajit-devel files not lua-devel files. It also looks for the shared library in the current directory or a few other places. So I can't simply put the file in the mod directory. If the shared library is found it works.

Re: Minetest, Luajit, and Javascript

PostPosted: 26 Oct 2016, 12:11
by dulsi
Scriptmine project has been created. Right now all it does is allow you to call javascript functions and echo. I don't have compiling/installing instructions up yet.

Re: Minetest, Luajit, and Javascript

PostPosted: 28 Oct 2016, 01:38
by mdtrooper
Good job, I follow this project. Thanks