From ba8c6e487d4ee6b36bd61335f552f5e1673ec4fb Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sat, 26 Jan 2013 17:07:44 +0000 Subject: [PATCH] Lunatic: use bcarray types to guard accesses to arrays inside structs. git-svn-id: https://svn.eduke32.com/eduke32@3435 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile | 3 +- polymer/eduke32/source/lunatic/con_lang.lua | 22 ++++----- polymer/eduke32/source/lunatic/defs.ilua | 51 ++++++++++----------- polymer/eduke32/source/lunatic/test.elua | 2 + 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/polymer/eduke32/Makefile b/polymer/eduke32/Makefile index a2a4624ab..1fcf0dc73 100644 --- a/polymer/eduke32/Makefile +++ b/polymer/eduke32/Makefile @@ -155,7 +155,8 @@ ifneq (0,$(LUNATIC)) $(OBJ)/luaJIT_BC_randgen.$o \ $(OBJ)/luaJIT_BC_stat.$o \ $(OBJ)/luaJIT_BC_bitar.$o \ - $(OBJ)/luaJIT_BC_control.$o + $(OBJ)/luaJIT_BC_control.$o \ + $(OBJ)/luaJIT_BC_bcarray.$o # now, take care of having the necessary symbols (sector, wall, etc.) in the # executable no matter what the debugging level diff --git a/polymer/eduke32/source/lunatic/con_lang.lua b/polymer/eduke32/source/lunatic/con_lang.lua index c433b7bbf..8b6e6cd65 100644 --- a/polymer/eduke32/source/lunatic/con_lang.lua +++ b/polymer/eduke32/source/lunatic/con_lang.lua @@ -441,8 +441,8 @@ local PlayerLabels = { last_extra = PL".last_extra", subweapon = PL".subweapon", - max_ammo_amount = { PL":get_max_ammo_amount(%s)" }, - ammo_amount = { PL":get_ammo_amount(%s)" }, + max_ammo_amount = PL".max_ammo_amount[%s]" , + ammo_amount = PL".ammo_amount[%s]" , -- NOTE: no direct access for .inv_amount (but see end) wackedbyactor = PL".wackedbyactor", @@ -487,7 +487,7 @@ local PlayerLabels = { last_pissed_time = PL".last_pissed_time", - weaprecs = { PL".weaprecs" }, + weaprecs = PL".weaprecs[%s]" , weapon_sway = PL".weapon_sway", crack_time = PL".crack_time", @@ -584,17 +584,17 @@ local PlayerLabels = { name = {}, -- Access to .inv_amount - steroids_amount = { PL":get_inv_amount(0)", }, - shield_amount = { PL":get_inv_amount(1)", }, - scuba_amount = { PL":get_inv_amount(2)", }, - holoduke_amount = { PL":get_inv_amount(3)", }, - jetpack_amount = { PL":get_inv_amount(4)", }, + steroids_amount = PL".inv_amount[0]", + shield_amount = PL".inv_amount[1]", + scuba_amount = PL".inv_amount[2]", + holoduke_amount = PL".inv_amount[3]", + jetpack_amount = PL".inv_amount[4]", -- 5: dummy -- 6: no "access_amount" - heat_amount = { PL":get_inv_amount(7)" }, + heat_amount = PL".inv_amount[7]", -- 8: dummy - firstaid_amount = { PL":get_inv_amount(9)" }, - boot_amount = { PL":get_inv_amount(10)" }, + firstaid_amount = PL".inv_amount[9]", + boot_amount = PL".inv_amount[10]", } local SEC = function(memb) return "sector[%s]"..memb end diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 7db39ac82..c04ff8544 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -152,6 +152,13 @@ local ACTOR_STRUCT = [[ } ]] +local bcarray = require("bcarray") + +-- TODO: randomize member names +bcarray.new("int16_t", 64, "loogie", "int16_x_64") +bcarray.new("int16_t", ffiC.MAX_WEAPONS, "weapon", "int16_x_MAX_WEAPONS") +bcarray.new("int16_t", ffiC.GET_MAX, "inventory", "int16_x_GET_MAX") + local DUKEPLAYER_STRUCT = [[ { vec3_t pos, opos, vel, npos; @@ -172,16 +179,16 @@ local DUKEPLAYER_STRUCT = [[ uint16_t max_actors_killed, actors_killed; uint16_t gotweapon, zoom; - const int16_t loogiex[64]; - const int16_t loogiey[64]; + int16_x_64 loogiex; + int16_x_64 loogiey; int16_t sbs, sound_pitch; int16_t ang, oang, angvel; const int16_t cursectnum; int16_t look_ang, last_extra, subweapon; - const int16_t max_ammo_amount[MAX_WEAPONS]; - const int16_t ammo_amount[MAX_WEAPONS]; - const int16_t inv_amount[GET_MAX]; + int16_x_MAX_WEAPONS max_ammo_amount; + int16_x_MAX_WEAPONS ammo_amount; + int16_x_GET_MAX inv_amount; int16_t wackedbyactor, pyoff, opyoff; int16_t horiz, horizoff, ohoriz, ohorizoff; @@ -199,7 +206,7 @@ local DUKEPLAYER_STRUCT = [[ const int16_t customexitsound; int16_t last_pissed_time; - const int16_t weaprecs[MAX_WEAPONS]; + int16_x_MAX_WEAPONS weaprecs; int16_t weapon_sway, crack_time, bobcounter; int16_t orotscrnang, rotscrnang, dead_flag; // JBF 20031220: added orotscrnang @@ -257,10 +264,9 @@ local function ma_replace_array(typestr, neltstr) local strtab = { "const ", typestr.." " } for i=1,nelts do local ch1 = 97 + (ma_rand:getu32() % 25) -- 'a'..'z' - strtab[i+2] = string.format("_%c%x%s", ch1, ma_count, (i 6) then + if (#args > 5) then error("invalid call to gameactor: must have at most six arguments", 2) end if (type(args[#args]) ~= "function") then diff --git a/polymer/eduke32/source/lunatic/test.elua b/polymer/eduke32/source/lunatic/test.elua index f33eec21d..9c45178db 100644 --- a/polymer/eduke32/source/lunatic/test.elua +++ b/polymer/eduke32/source/lunatic/test.elua @@ -250,6 +250,8 @@ gameevent(gv.EVENT_ENTERLEVEL, printf("sqrt(0xffffffff) = %f(ksqrt) %f(math.sqrt)", gv.ksqrt(0xffffffff), math.sqrt(0xffffffff)) + player[0].max_ammo_amount[gv.RPG_WEAPON] = 17 + checkfail("gameevent('GAME', function() print('qwe') end)", "must be called from top level") end