Lunatic: make con.ai accept literal action/move, check for calling from top.

Also, fix con._setgamepalette.

git-svn-id: https://svn.eduke32.com/eduke32@3541 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-03-03 16:06:37 +00:00
parent 596b3e6d6a
commit 0646e41fa4
4 changed files with 27 additions and 12 deletions

View File

@ -89,5 +89,11 @@ function bcheck.quote_idx(qnum, onlyidx)
return cstr
end
function bcheck.top_level(funcname)
if (ffiC.g_elCallDepth > 0) then
error("Invalid use of "..funcname..": must be called from top level", 3)
end
end
return bcheck

View File

@ -12,6 +12,7 @@ local bit = require("bit")
local io = require("io")
local math = require("math")
local geom = require("geom")
local bcheck = require("bcheck")
local con_lang = require("con_lang")
local byte = require("string").byte
@ -93,17 +94,19 @@ end
---=== ACTION / MOVE / AI ===---
function action(name, ...)
bcheck.top_level("action")
action_or_move("action", 5, def.action, name, ...)
end
function move(name, ...)
bcheck.top_level("move")
action_or_move("move", 2, def.move, name, ...)
end
-- Get action or move for an 'ai' definition.
local function get_action_or_move(what, val, argi)
if (val == nil) then
return {} -- will init the struct to all zeros
return {} -- ffi.new will init the struct to all zeros
elseif (type(val)=="string") then
local am = def[what][val]
if (am==nil) then
@ -112,13 +115,20 @@ local function get_action_or_move(what, val, argi)
return am
elseif (ffi.istype("con_"..what.."_t", val)) then
return val
elseif (type(val)=="number") then
if (val==0 or val==1) then
-- Create an action or move with an ID of 0 or 1 but all other
-- fields cleared.
return ffi.new("con_"..what.."_t", val)
end
end
-- TODO: literal number actions/moves?
error("bad argument #"..argi.." to ai: must be string or "..what, 3)
error("bad argument #"..argi.." to ai: must be string or (literal) "..what, 3)
end
function ai(name, action, move, flags)
bcheck.top_level("ai")
if (lastid.ai <= -(2^31)) then
error("Too many AIs defined", 2);
end
@ -143,7 +153,6 @@ end
---=== RUNTIME CON FUNCTIONS ===---
local bcheck = require("bcheck")
local check_sector_idx = bcheck.sector_idx
local check_tile_idx = bcheck.tile_idx
local check_sprite_idx = bcheck.sprite_idx
@ -1584,7 +1593,7 @@ function _setaspect(viewingrange, yxaspect)
end
function _setgamepalette(pli, basepal)
ffiC.P_SetGamePalette(player[pli], basepal)
ffiC.P_SetGamePalette(player[pli], basepal, 2+16)
end
-- Gamevar persistence in the configuration file

View File

@ -1360,9 +1360,7 @@ G_._G = G_
local gameactor_internal = gameactor_internal -- included in lunatic.c
-- gameactor(tilenum [, strength [, act [, mov [, movflags]]]], actor_func)
local function our_gameactor(tilenum, ...)
if (ffiC.g_elCallDepth > 0) then
error("Invalid use of gameactor: must be called from top level", 2)
end
bcheck.top_level("gameactor")
local args = {...}
if (type(tilenum) ~= "number") then

View File

@ -308,7 +308,8 @@ function on.actor_end(usertype, tsamm, codetab)
local str = ""
for i=2,math.min(#tsamm,4) do
if ((i==3 or i==4) and tsamm[i]=="0") then
-- HACK, gameactor() currently doesn't support literals
-- HACK, gameactor() currently doesn't support literals for actions
-- and moves.
tsamm[i] = "'NO'"
end
str = str .. tostring(tsamm[i])..","
@ -603,11 +604,12 @@ local function do_define_composite(labeltype, identifier, ...)
return
end
-- Fill up omitted arguments with zeros.
-- Fill up omitted arguments denoting composites with zeros.
local isai = (labeltype == LABEL.AI)
local args = {...}
for i=#args+1,labeltype do
-- passing nil to con.ai will make the action/move the null one
-- Passing nil/nothing as remaining args to con.ai will make the
-- action/move the null one.
args[i] = (isai and i<=2) and "nil" or 0
end