• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Lispy Repl and ~5K of symbols

Status
Not open for further replies.
Level 13
Joined
Nov 7, 2014
Messages
571
Lispy Repl and ~5K of symbols

The 'lispy-repl.lua' file allows one to evaluate Lisp-style expressions (because they are easy to parse).

Code:
(CreateUnit (Player 0) <hfoo> 0.0 0.0 270.0) -- creates a footman for player red
(table.pack 1 0x02 'three' #t nil ['this' 'is' 'a' 'list'])
(+ 1 2) -- the first "thing" inside of '(...)' must be a function or an operator

The code for the "Repl" detects strings that player red typed and begin with '$', it then evaluates them and prints the result (in a somewhat friendlier way than the 'print' function).

Lua:
local function on_input()
    local substr = string.sub

    local s = GetEventPlayerChatString()

    if '$' == substr(s, 1, 1) then
        local expr = substr(s, 2)

        local ret, err = lispy.eval(expr)
        if err ~= nil then
            print('error: ' .. err)
        else
            print_val(ret)
        end
    end
end

local function entry_point()
    local t = CreateTrigger()
    TriggerRegisterPlayerChatEvent(t, Player(0), '', '')
    TriggerAddAction(t, on_input)
end

The 'empty-map-symbols.txt' file is a list of symbols in the "global" scope (names of constants, variables, functions, built-in Lua "stuff") of an "empty" map that uses Lua rather than Jass. You could try to print some of them (e.g: '$ _VERSION').
 

Attachments

  • lispy-repl.lua.txt
    13.5 KB · Views: 38
  • empty-map-symbols.txt
    103.7 KB · Views: 34
Execute code using chat commands :), nice one.

My Tests (all worked):
$(SetPlayerState (Player 0) PLAYER_STATE_RESOURCE_GOLD 4900))
$(BlzSetUnitMaxHP udg_Unit 2334)
$(BlzSetAbilityRealLevelField (BlzGetUnitAbility udg_Unit <AHhb>) ABILITY_RLF_AMOUNT_HEALED_DAMAGED_HHB1 0 9999)
$(BlzCreateSimpleFrame 'SimpleInfoPanelIconDamage' (BlzGetOriginFrame ORIGIN_FRAME_GAME_UI 0) 44))
$(BlzFrameSetAbsPoint (BlzGetFrameByName 'InfoPanelIconBackdrop' 44) FRAMEPOINT_CENTER 0.4 0.3)
$(BlzFrameSetText (BlzGetFrameByName 'InfoPanelIconValue' 44) 'Some Test Text')

But the uploaded version crashes world editor when one validates code (with that also on save). I tested around a bit and the culpits seem to be:
function push_map
push_val = function(s, seen, x)

probably its '%' inside a string.
it worked after I added one additional %. For os.date and string.format one needs to use one additional % to have it working, like "%%.3f"

Edit: but I wonder how one uses true and false it seems to reject this words (undefined symbol 'false')
$(CustomVictoryBJ (Player 0) false true)
 
Last edited:
Level 13
Joined
Nov 7, 2014
Messages
571
But the uploaded version crashes world editor when one validates code (with that also on save). I tested around a bit and the culpits seem to be:
function push_map
push_val = function(s, seen, x)

probably its '%' inside a string.
it worked after I added one additional %. For os.date and string.format one needs to use one additional % to have it working, like "%%.3f"

I think this is a very old bug ('%' character in the custom script section). I can't find it mentioned anywhere earlier than in cJass's manual.
But even if it worked fine, I don't think one should be using a text box, which is what the World Editor gives you when using a custom script (unless I am missing something) for writing anything (maybe small 1-5 lines of "tests"). Even the simplest of text editors are much much more helpful than a text box...

You could maybe try mori's Ceres build tool. I just use a simple '.bat' "build file" that updates my map's war3map.lua file.

Edit: but I wonder how one uses true and false it seems to reject this words (undefined symbol 'false')
$(CustomVictoryBJ (Player 0) false true)

Code:
$ (CustomVictoryBJ (Player 0) #f #t)
 
I think this is a very old bug ('%' character in the custom script section). I can't find it mentioned anywhere earlier than in cJass's manual.
But even if it worked fine, I don't think one should be using a text box, which is what the World Editor gives you when using a custom script (unless I am missing something) for writing anything (maybe small 1-5 lines of "tests"). Even the simplest of text editors are much much more helpful than a text box...
World Editor gained this Script Files inside Trigger Editor which are a container for custom text like Triggers as custom Text without being a Trigger hence also don't need a InitTrig function.

$ (CustomVictoryBJ (Player 0) #f #t)
good to know.
 
Status
Not open for further replies.
Top