Skip to content

Commit

Permalink
fix sizeof usage
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Jun 30, 2015
1 parent 1ceefaf commit bdc2662
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rts/Lua/LuaUtils.h
Expand Up @@ -135,16 +135,16 @@ static void PushObjectDefProxyTable(
lua_State* L,
const char* indxOpers[3],
const char* iterOpers[2],
const IndexFuncType indxFuncs[3],
const IterFuncType iterFuncs[2],
const IndexFuncType (&indxFuncs)[3], // (&ident) preserves type for sizeof
const IterFuncType (&iterFuncs)[2], // (&ident) preserves type for sizeof
const ObjectDefType* def
) {
lua_pushnumber(L, def->id);
lua_newtable(L); { // the proxy table

lua_newtable(L); // the metatable

for (unsigned int n = 0; n < (sizeof(indxFuncs) / sizeof(indxFuncs[0])); n++) {
for (size_t n = 0; n < (sizeof(indxFuncs) / sizeof(indxFuncs[0])); n++) {
HSTR_PUSH(L, indxOpers[n]);
lua_pushlightuserdata(L, (void*) def);
lua_pushcclosure(L, indxFuncs[n], 1);
Expand All @@ -154,7 +154,7 @@ static void PushObjectDefProxyTable(
lua_setmetatable(L, -2);
}

for (unsigned int n = 0; n < (sizeof(iterFuncs) / sizeof(iterFuncs[0])); n++) {
for (size_t n = 0; n < (sizeof(iterFuncs) / sizeof(iterFuncs[0])); n++) {
HSTR_PUSH(L, iterOpers[n]);
lua_pushcfunction(L, iterFuncs[n]);
lua_rawset(L, -3);
Expand Down

4 comments on commit bdc2662

@jk3064
Copy link
Contributor

@jk3064 jk3064 commented on bdc2662 Jun 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::array?

@ashdnazg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke all defs for some reason

@cleanrock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When i start a game com do not show up and i see these errors which look bad:
[f=0000000] Error: LuaRules::RunCallIn: error = 2, Initialize, [Internal Lua error: Call failure] error = 2, LuaRules/gadgets.lua, error = 2, LuaGadgets/setupdefs.lua, [string "LuaGadgets/setupdefs.lua"]:18: attempt to perform arithmetic on field 'energyCost' (a nil value)
stack traceback:
[C]: in function 'Include'
[string "LuaRules/main.lua"]:53: in main chunk
[f=0000000] Error: LuaUI::RunCallIn: error = 2, Initialize, [Internal Lua error: Call failure] error = 2, LuaUI/setupdefs.lua, [string "LuaUI/setupdefs.lua"]:18: attempt to perform arithmetic on field 'energyCost' (a nil value)
stack traceback:
[C]: in function 'Include'
[string "LuaUI/utils.lua"]:53: in function 'include'
[string "-- $Id: camain.lua 3171 2008-11-06 09:06:29..."]:38: in function 'chunk'
[string "luaui.lua"]:55: in main chunk

@ashdnazg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using HSTR_PUSH inside a loop caused the wrong strings to be pushed since it declares a static const var.
Fixed in ad377e4

Please sign in to comment.