Commit Graph

39 Commits (3d037db789dd1cbdbefef7592d2398db6265b79c)

Author SHA1 Message Date
lethosor c1e2633e17 Refactor DFHack exception classes
Move implementations out of MiscUtils.cpp to Error.cpp and make what() return a
more useful description
2018-02-05 19:18:35 -05:00
lethosor 0332a5c25a Replace a call to abort() with a VTableMissing exception
This makes some scripts crash less when the viewscreen vtable is unavailable,
for example.
2017-12-25 20:13:15 -05:00
lethosor d280863bc8 Avoid iterating over "has-bad-pointers" fields of IDTYPE_STRUCT and others
dfhack/df-structures@4c224dd205
2017-08-05 21:34:16 -04:00
lethosor fa1adbbac4 Allow lua integer writes to accept anything that can be converted to an integer
May address #1044
2017-03-18 17:55:51 -04:00
lethosor 3bae9d9d65 Lua API: Make bitfield.whole return an integer, not a decimal 2016-12-10 12:27:43 -05:00
lethosor 9f541481ea Fix some warnings with GCC -Wall 2016-10-15 00:37:18 -04:00
lethosor 7b7f7a1b79 Fix support for integer fields in Lua 5.3 2016-07-28 16:36:02 -04:00
Vitaly Pronkin fe18f176f7 More 64-bit fixes
Cherry-picked from 7eb3ba6
- Lua update already done in e2c6350, 4dd411e
- Excluded library/modules/Buildings.cpp
2016-07-26 23:47:53 -04:00
lethosor 29a0aee44c Implement strnlen on OS X <= 10.6
Fixes #182
2015-08-24 17:51:42 -04:00
lethosor 2aba2da56d Avoid DataStaticsFields dependency on PluginManager.h 2015-08-11 22:59:19 -04:00
Alexander Gavrilov 6046d68639 Support std::fstream in data structures and add file_compressorst to xml.
One tricky thing is that fstream does not have operator=, so the new
file_compressorst requires a manually implemented one that skips it.
2014-09-24 22:47:04 +04:00
Petr Mrázek 8812238bf6 Update license, add contributors file, bump release number 2012-09-30 04:03:37 +02:00
Alexander Gavrilov e0097d8d43 Fix access to unnamed bits in bitfields, and allow hook.apply(false) 2012-09-01 11:25:24 +04:00
Alexander Gavrilov 30f71ff510 Implement support for lua-backed viewscreens. 2012-08-19 14:27:44 +04:00
Alexander Gavrilov c6694e386f Add rather inefficient type_identity wrapping for std::set.
Accessing an element is O(N), as if it was walking a list.
2012-08-18 14:34:20 +04:00
Alexander Gavrilov 149f175909 Make primitive refs (i.e. pointers to numbers, etc) behave as arrays. 2012-06-13 22:40:39 +04:00
Alexander Gavrilov 5afe2ca002 Update dfhack for specific_ref. 2012-05-03 11:47:04 +04:00
Alexander Gavrilov 2303a25bde Implement unconstructed building instance creation and linking into world.
For more flexibility, the base api is split into 3 phases:
alloc, setSize, and construct. No support for non-actual
buildings like stockpiles and activity zones at the moment.
2012-04-29 21:07:39 +04:00
Alexander Gavrilov 0a6982f404 Enable warnings correctly on linux and fix a lot of them. 2012-04-20 13:30:37 +04:00
Alexander Gavrilov 378a1fb914 Support the '#' string as index for wrapper vector insert at end. 2012-04-17 12:15:45 +04:00
Alexander Gavrilov 14709e5d45 Add an official core lua context, and allow plugins to send events to it.
- This context requires core suspend lock and asserts it in a few places.
- Special 'event' objects are introduced. They can be invoked as
  functions, in which case they iterate all their fields and call
  them as functions. Errors are printed and consumed.
- When a plugin is opened by the core context, events registered in
  a special array are linked to it. The system is organized so as to
  avoid even trying to pass the event to lua if the module isn't loaded.
2012-04-15 19:09:25 +04:00
Alexander Gavrilov cb49c92b99 Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
  checks the loaded state and locks a mutex in Plugin. If the plugin
  is unloaded, calling its functions throws a lua error. Therefore,
  plugins may not create closures or export yieldable functions.

- The set of function argument and return types supported by
  LuaWrapper is severely limited when compared to being compiled
  inside the main library.
  Currently supported types: numbers, bool, std::string, df::foo,
  df::foo*, std::vector<bool>, std::vector<df::foo*>.

- To facilitate postponing initialization until after all plugins
  have been loaded, the core sends a SC_CORE_INITIALIZED event.

- As an example, the burrows plugin now exports its functions.
2012-04-14 19:44:07 +04:00
Alexander Gavrilov 61245711f7 Export a few maps functions to lua. 2012-04-11 16:20:16 +04:00
Alexander Gavrilov 0e0740fddf Stop printall(df.global) from breaking if there are unknown addresses. 2012-04-10 10:34:03 +04:00
Alexander Gavrilov 9eed9f0d24 Wrap a few utility functions defined on the c++ side for lua. 2012-04-05 19:55:59 +04:00
Alexander Gavrilov 3afed43cdb Experimental: try wrapping a dfhack api function. 2012-04-05 11:59:39 +04:00
Alexander Gavrilov e3d50b9b04 Optimize wrapper: use pointers instead of strings as most frequent keys. 2012-04-01 18:34:04 +04:00
Alexander Gavrilov 9384f0c842 Update lua to 5.2 and fix obvious breakage due to obsolete api. 2012-03-31 12:11:43 +04:00
Alexander Gavrilov a9b7c74a23 Allow assigning NULL lightuserdata to pointers, and export a global.
Otherwise there is no way to specify NULL via recursive lua table assign.
2012-03-29 14:47:33 +04:00
Alexander Gavrilov 85c91c92d8 Implement __pairs and __ipairs for DF objects.
Structs enumerate fields in memory order in pairs().
Containers & biftields enumerate int indexes in ipairs, and
string keys in pairs (i.e. using index-enum for arrays).
2012-03-29 14:39:13 +04:00
Quietust 95ec363a7f Merge branch 'master' of https://github.com/peterix/dfhack
Conflicts:
	library/LuaTypes.cpp
	library/LuaWrapper.cpp
2012-03-28 11:51:49 -05:00
Alexander Gavrilov 929657bed4 Disable pointer auto-vivification unless new is specified.
Since it is essentially allocating non-gc managed objects,
it can lead to memory leaks and shouldn't happen invisibly.
Also support using the 'assign' key to request assign()
from another object before processing the current map.
2012-03-28 17:00:07 +08:00
Alexander Gavrilov b76bdad50f Implement recursive transfer of values from lua to c++ structures.
E.g. df.global.cursor = { x = 1, y = 2, z = 3 }. The lua data
must be represented by raw lua tables.

For structs, the entries in the table are assigned to matching fields.

For containers, if a 'resize' field is missing or nil, the table is
treated like 1-based lua array, and the container is resized to match
its # length. Otherwise, the field must be either an explicit number,
true or false. If it is true, the size is selected by the highest index
in the table. After that, entries are copied using 0-based indices.

For pointers, the table must match the target object. If the pointer
is null, the object is auto-allocated; this can be controlled using
the 'new' field, the value of which will be passed to df.new().
2012-03-28 16:58:51 +08:00
Alexander Gavrilov bc74c5984e Implement recursive transfer of values from lua to c++ structures.
E.g. df.global.cursor = { x = 1, y = 2, z = 3 }. The lua data
must be represented by raw lua tables.

For structs, the entries in the table are assigned to matching fields.

For containers, if a 'resize' field is missing or nil, the table is
treated like 1-based lua array, and the container is resized to match
its # length. Otherwise, the field must be either an explicit number,
true or false. If it is true, the size is selected by the highest index
in the table. After that, entries are copied using 0-based indices.

For pointers, the table must match the target object. If the pointer
is null, the object is auto-allocated; this can be controlled using
the 'new' field, the value of which will be passed to df.new().
2012-03-27 21:47:52 +04:00
Alexander Gavrilov 1d81cb56ba Make enum attributes accessible through the lua wrapper.
TODO: make them completely read-only.
2012-03-25 19:12:59 +04:00
Alexander Gavrilov 7209e4d3f2 Attach static methods to the type objects in the lua wrapper. 2012-03-25 15:20:58 +04:00
Alexander Gavrilov 8d345be6e7 Expose virtual methods in the lua wrapper. 2012-03-25 14:06:05 +04:00
Alexander Gavrilov 0c7fc233bd Support resize/erase/insert for containers, and allow any index in BitArray. 2012-03-24 16:28:53 +04:00
Alexander Gavrilov d865d54a90 Split LuaWrapper.cpp into two files. 2012-03-24 13:25:10 +04:00