Skip to content
Jeroen Broks edited this page Aug 15, 2020 · 1 revision

Exports the contents of a Neil identifier into a pure Lua identifier.

This test script may illustrate the workings

Void Hello()
        Print("Hello World!")
End

Init
        Export Hello Hi
        #pure
                Hi()
                Hello() -- Not known by Lua, so would cause an error!
        #endpure
End

Since "Hello" is a Neil function, Lua wouldn't know how to handle it. The reason Lua executes all Neil functions and reads and assigns all Neil variables properly is because Neil automatically makes the proper references so Lua will understand. However, sometimes pure Lua code can be needed, or rather Lua needs to be able to call an entire set of functions and stuff set up in Neil, from a normal Lua script... After all Lua is able to import simply by calling "Neil.Use()" from a pure Lua script. For a Lua coder who doesn't know Neil, all that's important is to do make a "Neil = require 'Neil'; Neil.Use("whateever")" has to be done to import your Neil script... Now this is where "Export" can be handy.

If you plan to use Neil in pre-made Lua engines, having a nasty set up of callback functions export can also be your savior. Take LÖVE2d for example:

LoveDemo.neil

import love
Void love_draw()
    love.graphics.print("Hello World", 400, 300) // with "love" imported this will just be called normally!
end

Init
   Export love_draw "love.draw"
   // mind the quotes, as the "." was used
End

main.lua

Neil = require "Neil"
Neil.Use("LoveDemo")

I did not test the code above, but it SHOULD work.

Now "Export" can be a bit obsolete here, as you can also do it like this:

Init
   Import love
   love.draw = Void()
         love.graphics.print("Hello World", 400, 300)
   End
End

It's just what you prefer... Similar approaches will work well with other engines too..

Important note... Export is not safe... It makes no bones whatsoever about how stuff is exported. It will overwrite stuff already defined in Lua without second thought, and if you set it to Neil will try to overwrite Lua keywords (although Lua won't let it happen and thus cause a crash on the compiling stage, but Neil doesn't care about that). Using Import and Export should therefore be used with care.